Kinds
of Inheritance
In Java inheritance is
used for two main purposes:
Class
Inheritance - create a new class as an extension of another class primarily for
the purpose of code reuse. That is, the derived class inherits the public
methods and public data of the base class. Java only allows a class to have one
immediate base class i.e. single class inheritance.
public
class derived-class-name extends
base-class-name {
// derived class methods extend and possibly override
// those of the base class
}
Interface
Inheritance – create a new class
to implement the methods defined as part of an interface for the purpose of
subtyping. That is a class that implements an interface conforms to the
interface.
public
class class-name implements
interface-name {
// class provides an implementation for the methods
// as specified by the interface