©1994-2003 Kevin Boone
Home     Section index     K-Zone home Simple Java programs

Site search

Glossary
Confused by computer jargon? Look it up!

Shameless plug


Now available!

Articles
- Ten-minute guide to setting up a WAP site

- Talk like your boss: new developments in managerese

More...

Development
File handling in the Linux kernel

Java development for the Sony-Ericsson P800

SunONE Application Server 7 FAQ

More...

Linux
Using Linux with the Treo 600

- Linux on the Tecra M1

- Some notes on openzaurus

More...

Download
Java stuff

Linux stuff

More...

(Please read the download policy)

Home automation
The X10 system

Linux TW723 driver

More...

The K-Zone
K-Zone computing

K-Zone law

K-Zone education and science

K-Zone motorcycles

K-Zone DIY

K-Zone railways

K-Zone martial arts

About the author

K-Zone home page

 
Software development
Computing
Hello1.java
Add1.java
Add1_1.java
AwtTest.java
Button1.java
Button2.java
Calculator.java
CalculatorApp.java
ClockApplet.java
CountSpace1.java
DateTime.java
Div1.java
DoNothing.java
Factorial1.java
Factorial2.java
FontChooser.java
IfTest.java
Loan.java
DiceThrower.java
MultiplicationTable.java
Queue.java
Reverse1.java
SoundApplet.java
Stressometer.java
TextReaderTest.java
WebMerge.java
Zener.java
`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";
	}
}