Checkout
checkout
view
Your Cart Your Cart: item(s)
Subjects -> Computer Science -> Other -> Posting #3148
Add to Shopping Cart
$2.19 Instant Download
Computer Science, Other
Year 1

Explain the usage of "Inheritence" with a sample program


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; }
}

By OTA:  Chockalingam Annamalai, MCA

OTA Rating:  n/a

What's included:

  • Plain text response
$2.19 Download Add to Cart

Add to Shopping Cart
$2.19 Instant Download

Page generated in 0.0122 seconds

About Us ·  Contact Us ·  Samples ·  Solutions ·  Legal Terms and Conditions ·  Privacy Policy

©2008 SolutionLibrary.com

Search for Solutions About Us Samples