logo Practice-It logo

inheritanceMystery

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

Assume that the following classes have been defined:

public class Biggie extends JayZ {
    public void a() {
        System.out.print("Biggie a   ");
        super.a();
    }

    public String toString() {
        return "Biggie";
    }
}

public class JayZ extends Tupac {
    public void a() {
        System.out.print("JayZ a   ");
        b();
    }
}
public class FiftyCent extends Biggie {
    public void b() {
        System.out.print("FiftyCent b   ");
    }
}
public class Tupac {
    public void a() {
        System.out.print("Tupac a   ");
    }

    public void b() {
        System.out.print("Tupac b   ");
    }

    public String toString() {
        return "Tupac";
    }
}

Given the classes above, what output is produced by the following code?

Tupac[] elements = {new Biggie(), new Tupac(), new JayZ(), new FiftyCent()};
for (int i = 0; i < elements.length; i++) {
    elements[i].a();
    System.out.println();
    elements[i].b();
    System.out.println();
    System.out.println(elements[i]);
    System.out.println();
}
elements[0]: Biggie
elements[1]: Tupac
elements[2]: JayZ
elements[3]: FiftyCent

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.