Explore BrainMass

Explore BrainMass

    What is the output of this Java program?

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    What is the output of this Java program?

    public class InheritanceProblem
    {
    public static void main(String[] args)
    {
    System.out.println(new X().message());
    System.out.println(new Y().message());
    System.out.println(new Z().message());
    }
    }
    class X
    {
    String size, color;
    X() { this("BIG","RED"); }
    X(String s, String c) { size = s; color = c; }
    public String message() { return "I am " + description() + "."; }
    protected String description() { return size + " and " + color; }
    }
    class Y extends X
    {
    Y() { super("SMALL","RED"); }
    public String message() {return "I wish I were " + description() + ".";}
    }
    class Z extends X
    {
    Z() { super("BIG","BLUE"); }
    protected String description() { return size + " but not " + color; }
    }

    © BrainMass Inc. brainmass.com February 24, 2021, 2:07 pm ad1c9bdddf
    https://brainmass.com/computer-science/java/what-is-the-output-of-this-java-program-3148

    Solution Summary

    What is the output of this Java program?

    $2.19

    ADVERTISEMENT