logo Practice-It logo

BlueRedYellowGreen

Author: Marty Stepp (on 2010/12/28)

Consider the following classes:

public class Blue extends Green {
    public void one() {
        System.out.println("Blue 1");
        super.one();
    }
}

public class Red extends Yellow {
    public void one() {
        super.one();
        System.out.println("Red 1");
    }
    
    public void two() {
        System.out.println("Red 2");
        super.two();
    }
}

public class Yellow extends Blue {
    public void two() {
        System.out.println("Yellow 2");
    }

    public void three() {
        two();
        System.out.println("Yellow 3");
    }
}

public class Green {
    public void one() {
        System.out.println("Green 1");
    }

    public void three() {
        System.out.println("Green 3");
    }
}

Suppose the following variables are defined:

Green var1 = new Blue();
Green var2 = new Red();
Blue var3 = new Yellow();
Object var4 = new Green();

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.one();
var1.two();
var1.three();
var2.one();
var2.three();
var3.one();
var3.two();
var3.three();
var4.one();
((Blue) var1).one();
((Yellow) var1).two();
((Red) var2).three();
((Object) var3).one();
((Yellow) var3).two();
((Green) var4).three();
((Red) var4).one();

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.