What is the output of inheritance problem


Discussion:

Q: What is the output of below 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; }
}

Solution Preview :

Prepared by a verified Expert
JAVA Programming: What is the output of inheritance problem
Reference No:- TGS01935928

Now Priced at $20 (50% Discount)

Recommended (96%)

Rated (4.8/5)