Description
Assume that the following classes have been defined:
public class Quadrilateral
{
public String name = “Quadrilateral”;
public void method1()
{
System.out.println(“Quadrilateral 1”);
}
public void method2()
{
System.out.println(“Quadrilateral 2”);
}
public void method3()
{
System.out.println(“Quadrilateral 3”);
}
public void method4()
{
System.out.println(“Quadrilateral 4”);
}
public String toString(){
this.method4();
return “This is Quadrilateral Class”;
}
}
public class Trapezium extends Quadrilateral
{
public String name = “Trapezium”;
public void method1(){
System.out.println(“Trapezium 1”);
}
public String toString(){
return “This is a “+ name;
}
}
public class Kite extends Quadrilateral
{
public String name = “Kite”;
public void method1()
{
System.out.println(“Kite 1”);
}
public void method3()
{
System.out.println(“Kite 3”);
}
public void method4()
{
System.out.println(“Kite 4”);
}
}
public class Parallelogram extends Quadrilateral
{
public String name = “Parallelogram”;
public void method3()
{
System.out.println(“Parallelogram 3”);
super.method2();
method4();
}
}
public class Rhombus extends Parallelogram
{
public String name = “Rhombus”;
public void method1(){
System.out.println(this);
System.out.println(“Rhombus 1”);
}
public void method3(){
super.method2();
System.out.println(“Rhombus 3”);
}
}
public class Rectangle extends Parallelogram
{
public String name = “Rectangle”;
public void method2(){
method4();
System.out.println(“Rectangle 2”);
System.out.println(this);
}
public int compareTo(Rectangle a){
if(a instanceof Rectangle){
return 1;
}else{
return 0;
}
}
}
public class Square extends Rectangle
{
public String name = “Square”;
public void method1(){
method3();
System.out.println(“Square 1”);
}
public void method2(){
super.method2();
System.out.println(“Square 2”);
method3();
}
}
And assume that the following variables have been defined:
Quadrilateral shape1 = new Quadrilateral();
Object shape2 = new Kite();
Quadrilateral shape3 = new Trapezium();
Object shape4 = new Parallelogram();
Parallelogram shape5 = new Rhombus();
Quadrilateral shape6 = new Rectangle();
Parallelogram shape7 = new Square();
Rectangle shape8 = new Square();
In the table below, indicate in the right-hand column the output produced by the statement in the left-hand column. If the statement produces more than one line of output, indicate the line breaks with slashes as in “a/b/c” which indicates three lines of output with “a” followed by “b” followed by “c”. If the statement causes an error, fill in the right-hand column with either โCTโ for โcompile time error” or RE for “runtime error” to indicate when the error would be detected.
Statement Output
System.out.println(shape1.name);
System.out.println(shape2.name);
System.out.println(shape3.name);
System.out.println(shape4.name);
System.out.println(shape5.name);
System.out.println(shape6.name);
System.out.println(shape7.name);
shape1.method1();
shape1.method2();
shape1.method3();
shape1.method4();
shape2.method1();
shape2.method2();
shape2.method3();
shape2.method4();
shape3.method1();
shape3.method2();
shape3.method3();
shape3.method4();
shape4.method1();
shape4.method2();
shape4.method3();
shape4.method4();
shape5.method1();
shape5.method2();
shape5.method3();
shape5.method4();
shape6.method1();
shape6.method2();
shape6.method3();
shape6.method4();
shape7.method1();
shape7.method2();
shape7.method3();
shape7.method4();
System.out.println(shape8.compareTo(shape8));
((Quadrilateral) shape1).method1();
((Quadrilateral) shape2).method1();
((Quadrilateral) shape3).method1();
((Quadrilateral) shape4).method1();
((Quadrilateral) shape5).method1();
((Quadrilateral) shape6).method1();
((Quadrilateral) shape7).method1();
((Quadrilateral) shape1).method2();
((Quadrilateral) shape2).method2();
((Quadrilateral) shape3).method2();
((Quadrilateral) shape4).method2();
((Quadrilateral) shape5).method2();
((Quadrilateral) shape6).method2();
((Quadrilateral) shape7).method2();
((Quadrilateral) shape1).method3();
((Quadrilateral) shape2).method3();
((Quadrilateral) shape3).method3();
((Quadrilateral) shape4).method3();
((Quadrilateral) shape5).method3();
((Quadrilateral) shape6).method3();
((Quadrilateral) shape7).method3();
((Object) shape1).method1();
((Object) shape2).method1();
((Object) shape3).method1();
((Object) shape4).method1();
((Object) shape5).method1();
((Object) shape6).method1();
((Object) shape7).method1();
((Object) shape1).method2();
((Object) shape2).method2();
((Object) shape3).method2();
((Object) shape4).method2();
((Object) shape5).method2();
((Object) shape6).method2();
((Object) shape7).method2();
((Object) shape1).method3();
((Object) shape2).method3();
((Object) shape3).method3();
((Object) shape4).method3();
((Object) shape5).method3();
((Object) shape6).method3();
((Object) shape7).method3();
((Kite) shape1).method1();
((Kite) shape2).method1();
((Kite) shape3).method1();
((Kite) shape4).method1();
((Kite) shape5).method1();
((Kite) shape6).method1();
((Kite) shape7).method1();
((Kite) shape1).method2();
((Kite) shape2).method2();
((Kite) shape3).method2();
((Kite) shape4).method2();
((Kite) shape5).method2();
((Kite) shape6).method2();
((Kite) shape7).method2();
((Kite) shape1).method3();
((Kite) shape2).method3();
((Kite) shape3).method3();
((Kite) shape4).method3();
((Kite) shape5).method3();
((Kite) shape6).method3();
((Kite) shape7).method3();
((Parallelogram) shape1).method1();
((Parallelogram) shape2).method1();
((Parallelogram) shape3).method1();
((Parallelogram) shape4).method1();
((Parallelogram) shape5).method1();
((Parallelogram) shape6).method1();
((Parallelogram) shape7).method1();
((Parallelogram) shape1).method2();
((Parallelogram) shape2).method2();
((Parallelogram) shape3).method2();
((Parallelogram) shape4).method2();
((Parallelogram) shape5).method2();
((Parallelogram) shape6).method2();
((Parallelogram) shape7).method2();
((Parallelogram) shape1).method3();
((Parallelogram) shape2).method3();
((Parallelogram) shape3).method3();
((Parallelogram) shape4).method3();
((Parallelogram) shape5).method3();
((Parallelogram) shape6).method3();
((Parallelogram) shape7).method3();
((Trapezium) shape1).method1();
((Trapezium) shape2).method1();
((Trapezium) shape3).method1();
((Trapezium) shape4).method1();
((Trapezium) shape5).method1();
((Trapezium) shape6).method1();
((Trapezium) shape7).method1();
((Trapezium) shape1).method2();
((Trapezium) shape2).method2();
((Trapezium) shape3).method2();
((Trapezium) shape4).method2();
((Trapezium) shape5).method2();
((Trapezium) shape6).method2();
((Trapezium) shape7).method2();
((Trapezium) shape1).method3();
((Trapezium) shape2).method3();
((Trapezium) shape3).method3();
((Trapezium) shape4).method3();
((Trapezium) shape5).method3();
((Trapezium) shape6).method3();
((Trapezium) shape7).method3();
((Rhombus) shape1).method1();
((Rhombus) shape2).method1();
((Rhombus) shape3).method1();
((Rhombus) shape4).method1();
((Rhombus) shape5).method1();
((Rhombus) shape6).method1();
((Rhombus) shape7).method1();
((Rhombus) shape1).method2();
((Rhombus) shape2).method2();
((Rhombus) shape3).method2();
((Rhombus) shape4).method2();
((Rhombus) shape5).method2();
((Rhombus) shape6).method2();
((Rhombus) shape7).method2();
((Rhombus) shape1).method3();
((Rhombus) shape2).method3();
((Rhombus) shape3).method3();
((Rhombus) shape4).method3();
((Rhombus) shape5).method3();
((Rhombus) shape6).method3();
((Rhombus) shape7).method3();
((Rectangle) shape1).method1();
((Rectangle) shape2).method1();
((Rectangle) shape3).method1();
((Rectangle) shape4).method1();
((Rectangle) shape5).method1();
((Rectangle) shape6).method1();
((Rectangle) shape7).method1();
((Rectangle) shape1).method2();
((Rectangle) shape2).method2();
((Rectangle) shape3).method2();
((Rectangle) shape4).method2();
((Rectangle) shape5).method2();
((Rectangle) shape6).method2();
((Rectangle) shape7).method2();
((Rectangle) shape1).method3();
((Rectangle) shape2).method3();
((Rectangle) shape3).method3();
((Rectangle) shape4).method3();
((Rectangle) shape5).method3();
((Rectangle) shape6).method3();
((Rectangle) shape7).method3();
((Square) shape1).method1();
((Square) shape2).method1();
((Square) shape3).method1();
((Square) shape4).method1();
((Square) shape5).method1();
((Square) shape6).method1();
((Square) shape7).method1();
((Square) shape1).method2();
((Square) shape2).method2();
((Square) shape3).method2();
((Square) shape4).method2();
((Square) shape5).method2();
((Square) shape6).method2();
((Square) shape7).method2();
((Square) shape1).method3();
((Square) shape2).method3();
((Square) shape3).method3();
((Square) shape4).method3();
((Square) shape5).method3();
((Square) shape6).method3();
((Square) shape7).method3();
Reviews
There are no reviews yet.