Instructors' Guide
Introduction
Terminology
Expressions
Control
Objects
Inheritance
Technology
Summary
Inheritance
In Java, all classes are derived from the
class Object, defined in the package java.lang.
As an advantage, every object class defined in Java
is known to support a number of basic methods,
such as clone, equals, finalize, hashCode,
toString. Of course, the programmer of the class
is responsible for redefining these methods if appropriate.
For example, when the method clone is invoked,
the object throws an exception unless
the method clone has been defined.
The following members of Object, however,
cannot be overridden:
getClass, notify, notifyAll, wait.
The latter three reflect Java's support for threads;
they should not be used when the object is not a thread.
Hello World -- Java (2)
import java.awt.Graphics;
public class HelloWorld extends java.applet.Applet {
public void init() { resize(150,50); }
public void paint(Graphics g) {
g.drawString("Hello, World!", 50, 25);
}
};
slide: Java -- inheritance
A simple example of a class that inherits from the
Java Applet class is given in slide [Java-inheritance].
It redefines the init and the paint method,
which says `Hello World'.