What option suitably represents the necessary code?

You are employed as a developer at ABC.com. You make use of C# and ASP.NET for
development purposes.
You are instructed to develop a new Rectangle class. The new class should allow for Rectangle
objects to be compared.
What option suitably represents the necessary code?

You are employed as a developer at ABC.com. You make use of C# and ASP.NET for
development purposes.
You are instructed to develop a new Rectangle class. The new class should allow for Rectangle
objects to be compared.
What option suitably represents the necessary code?

A.
class Rectangle : IConvertible
{
public double Length { get; set; }
public double Width { get; set; }
public double GetArea()
{
return Length * Width;
}
public intCompareTo(object obj)
{
Rectangle target = (Rectangle)obj;
double diff = this.GetArea() – target.GetArea();
if (diff == 0)
return 0;
else if (diff > 0)
return 1;
else return -1;
}
}

B.
class Rectangle : IComparable
{
public Length { get; set; }
public Width { get; set; }
public GetArea()
{
return Area;
}
public intCompareTo(object obj)
{
Rectangle target = (Rectangle)obj;
double diff = this.GetArea() – target.GetArea();
if (diff == 0)
return 0;
else if (diff > 0)
return 1;
else return -1;
}
}

C.
class Rectangle : IComparable
{
private double Length { get; set; }
private double Width { get; set; }
private double GetArea()
{
return Length * Width;
}
private intCompareTo(object obj)
{
Rectangle target = (Rectangle)obj;
double diff = this.GetArea() – target.GetArea();
if (diff == 0)
return 0;
else if (diff > 0)
return 1;
else return -1;
}
}

D.
class Rectangle : IComparable
{
private Length { get; set; }
private Width { get; set; }
private GetArea()
{
return Area;
}
private intCompareTo(object obj)
{
Rectangle target = (Rectangle)obj;
double diff = this.GetArea() – target.GetArea();
if (diff == 0)
return 0;
else if (diff > 0)
return 1;
else return -1;
}
}



Leave a Reply 4

Your email address will not be published. Required fields are marked *


Havret

Havret

Answer C is incorrect! IConvertible? WTF?

louay abdelhedi

louay abdelhedi

C is the correct answer.

Fredy

Fredy

The correct answer is B because CompareTo method cannot be more restrictive than method defined on interface.

Hoong

Hoong

The correct answer is A. Its not necessary implement interface IComparable.
C: Due to private access modifiers caused not able assign value the properties.