Question: Java Practice Inheritance Problem Assuming that the following classes have been defined: public class Block extends Truck { public void method1() { System.out.println(Block 1); }

Java

Practice Inheritance Problem

Assuming that the following classes have been defined:

public class Block extends Truck {

public void method1() {

System.out.println("Block 1");

}

public void method3() {

System.out.println("Block 3");

}

}

public class Doll extends Ball {

public void method1() {

System.out.println("Doll 1");

}

public void method2() {

System.out.println("Doll 2");

}

}

public class Truck extends Ball {

public void method2() {

System.out.println("Truck 2");

super.method2();

method3();

}

public void method3() {

System.out.println("Truck 3");

}

}

public class Ball {

public void method2() {

System.out.println("Ball 2");

}

public void method3() {

System.out.println("Ball 3");

}

}

And assuming the following variables have been defined:

Ball var1 = new Truck();

Doll var2 = new Doll();

Ball var3 = new Block();

Object var4 = new Ball();

Truck var5 = new Block();

Ball var6 = new Doll();

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" to indicate 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 the phrase "compiler error" or "runtime error" to indicate when the error would be detected.

Statement Output

------------------------------------------------------------

var1.method1(); ____________________________

var2.method1(); ____________________________

var1.method2(); ____________________________

var2.method2(); ____________________________

var3.method2(); ____________________________

var4.method2(); ____________________________

var5.method2(); ____________________________

var1.method3(); ____________________________

var2.method3(); ____________________________

var3.method3(); ____________________________

var4.method3(); ____________________________

var5.method3(); ____________________________

((Doll)var3).method1(); ____________________________

((Block)var5).method1(); ____________________________

((Truck)var3).method1(); ____________________________

((Truck)var3).method3(); ____________________________

((Block)var6).method3(); ____________________________

((Ball)var4).method2(); ____________________________

((Truck)var4).method3(); ____________________________

((Doll)var6).method3(); ____________________________

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!