Important Notice:

Practice-It will be discontinued as of November 1st, 2024. After this date, the website will remain online for a transitional period, but login will be restricted to University of Washington NetID authentication. This marks the next phase towards the platform's full retirement. Thank you for your use and support of the application over the years.

If you are looking for an alternative, a similar tool, CodeStepByStep, was developed independently by the original author of Practice-It, and is available at codestepbystep.com**

logo Practice-It logo

PolarBearTeddyPooh

Author: Allison Obourn (on 2012/08/29)

Consider the following classes:

public class Polar extends Bear {
    public void b() {
        a();
        System.out.println("Polar 2");
    }

    public void c() {
        System.out.println("Polar 3");
    }
}

public class Bear {
    public void a() {
        System.out.println("Bear 1");
        c();
    }

    public void c() {
        System.out.println("Bear 3");
    }
}

public class Pooh extends Teddy {
    public void b() {
        System.out.println("Pooh 2");
        super.c();
    }

    public void c() {
        System.out.println("Pooh 3");
    }
}

public class Teddy extends Bear {
    public void a() {
        System.out.println("Teddy 3");
        super.a();
    }
}

Suppose the following variables are defined:

Bear   var1 = new Teddy();
Pooh   var2 = new Pooh();
Bear   var3 = new Polar();
Bear   var4 = new Pooh();
Object var5 = new Teddy();

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.a();
var1.c();
var2.a();
var2.b();
var3.a();
var3.b();
var4.a();
var5.a();
((Pooh) var5).a();
((Teddy) var1).a();
((Teddy) var4).a();
((Pooh) var3).b();
((Polar) var3).b();
((Teddy) var4).c();
((Bear) var5).c();

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.