logo Practice-It logo

AnimalVegetableMineralComputer

Author: Marty Stepp (on 2011/03/17)

Consider the following classes:

public class Computer extends Mineral {
    public void b() {
        System.out.println("Computer b");
        super.b();
    }
        
    public void c() {
        System.out.println("Computer c");
    }
}

public class Mineral extends Vegetable {
    public void b() {
        System.out.println("Mineral b");
        a();
    }
}

public class Animal extends Mineral {
    public void a() {
        System.out.println("Animal a");
    }
    
    public void c() {
        b();
        System.out.println("Animal c");
    }
}

public class Vegetable {
    public void a() {
        System.out.println("Vegetable a");
    }

    public void b() {
        System.out.println("Vegetable b");
    }
}

Suppose the following variables are defined:

Vegetable var1 = new Computer();
Mineral   var2 = new Animal();
Vegetable var3 = new Mineral();
Object    var4 = new Mineral();

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.b();
var1.c();
var2.a();
var2.b();
var3.a();
var3.b();
var4.a();
((Computer) var1).b();
((Computer) var1).c();
((Computer) var2).c();
((Animal) var2).c();
((Computer) var3).b();
((Vegetable) var4).b();
((Animal) var4).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.