logo Practice-It logo

LeoMikeRaphDon

Author: Marty Stepp

Consider the following classes:

public class Leo extends Don {
    public void method1() {
        System.out.println("Leo 1");
    }
    
    public void method3() {
        System.out.println("Leo 3");
        method1();
    }
}

public class Mike extends Leo {
    public void method2() {
        System.out.println("Mike 2");
        super.method2();
    }
}

public class Raph {
    public void method1() {
        System.out.println("Raph 1");
    }
}

public class Don extends Raph {
    public void method2() {
        method1();
        System.out.println("Don 2");
    }
}

Suppose the following variables are defined:

Raph var1   = new Don();
Leo var2    = new Mike();
Object var3 = new Raph();
Don var4    = new Leo();

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.method1();
var1.method2();
var1.method3();
var2.method1();
var2.method2();
var2.method3();
var3.method1();
var4.method1();
var4.method2();
var4.method3();
((Don) var1).method2();
((Mike) var2).method2();
((Raph) var3).method1();
((Don) var3).method2();
((Leo) var4).method3();

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.