Question: Suppose that the following variables referring to the classes from the previous problem are declared: Pond var1 = new Bay(); Object var2 = new Ocean();

Suppose that the following variables referring to the classes from the previous problem are declared:

Pond var1 = new Bay();

Object var2 = new Ocean();

Which of the following statements produce compiler errors? For the statements that do not produce errors, what is the output of each statement?

((Lake) var1).method1();

((Bay) var1).method1();

((Pond) var2).method2();

((Lake) var2).method2();

((Ocean) var2).method3();


Data from Previous Problem

Assume that the following classes have been defined:

1 public class Bay extends Lake { public void method1 () { 3 System.out.print (

1 public class Bay extends Lake { public void method1 () {

What output is produced by the following code fragment?

3 System.out.print ("Bay 1 "); 4 super.method2 (); public void method2 ()

1 public class Bay extends Lake { public void method1 () { 3 System.out.print ("Bay 1 "); 4 super.method2 (); public void method2 () { 7 System.out.print ("Bay 2 "); } 1 public class Pond { public void methodl () { 3. System.out.print ("Pond 1 "); 4 public void method2 () { System.out.print ("Pond 2 "); 8 public void method3 () { 9 System.out.print ("Pond 3 "); 10 11 } 6. 9.

Step by Step Solution

3.39 Rating (165 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

None of the statements produce ... View full answer

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 Building Java Programs A Back to Basics Approach Questions!