`Inheritance1' example program: demonstrates inheritance; work out what the result should be

Inheritance1.java

/* 
Inheritance1

What output does this applet produce? Try to work it out
before running the program

Kevin Boone, August 1999
*/

import java.applet.Applet;
import java.awt.*;

/*
*/

public class Inheritance1 extends Applet 
{
String s;
public Inheritance1()
	{
	s = "aaa";	
	}

public void paint (Graphics g)
	{
	Inheritance2 i2 = new Inheritance2();
	String s = i2.getData();
	g.drawString(s, 20, 20);
	}

}

class Inheritance2 extends Inheritance3
{
public Inheritance2()
	{
	super();
	s = s + "bbb";
	}

public String getData()
	{
	return s;
	}
}

class Inheritance3
{
String s = "ccc";

public Inheritance3()
	{
	super();
	s = "ddd";
	}

public String getData()
	{
	return "eee";
	}
}





©1994-2003 Kevin Boone, all rights reserved