logo Practice-It logo

BayPondOceanLake

Author: Robert Baxter

Consider the following classes:

public class Bay extends Lake {
    public void method1() {
        System.out.println("Bay 1");
        super.method2();
    }

    public void method2() {
        System.out.println("Bay 2");
    }
}

public class Pond {
    public void method2() {
        System.out.println("Pond 2");
    }
}

public class Ocean extends Bay {
    public void method2() {
        System.out.println("Ocean 2");
    }
}

public class Lake extends Pond {
    public void method3() {
        System.out.println("Lake 3");
        method2();
    }
}

Suppose the following variables are defined:

Lake var1 = new Ocean();
Pond var2 = new Pond();
Pond var3 = new Lake();
Object var4 = new Bay();
Lake var5 = new Bay();
Bay var6 = new Ocean();

Indicate on each line below the output produced by each statement shown. 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, write the word error to indicate this.

var1.method2();
var2.method2();
var3.method2();
var4.method2();
var5.method2();
var6.method2();
var1.method3();
var2.method3();
var3.method3();
var4.method3();
var5.method3();
var6.method3();
((Ocean) var5).method1();
((Lake) var3).method3();
((Lake) var4).method1();
((Ocean) var1).method1();
((Bay) var4).method1();
((Lake) var2).method3();
((Ocean) var5).method1();
((Pond) var4).method2();

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.