Inheritance
allows a class to acquire the members of another class. In the following example,
Apple inherits from
Fruit. This is specified with the
extends keyword.
Fruit then becomes the superclass of Apple, which in turn becomes a subclass of
Fruit. In addition to its own members,
Apple gains all accessible members in
Fruit, except for any constructors.
// Superclass (parent class)
class Fruit
{
public String flavor;
}
// Subclass (child class)
class Apple extends Fruit
{
public String variety;
}
A class in Java may only inherit from one superclass, and if no class is specified, ...