Inheritance in Java
We
can create a general class that defines traits common to a set of
related items.
This
class can then be inherited by others,
more specific classes, each adding those things that
are unique to it
A
classes that is inherited are called a super classes. The classes that does the inheritance is
called a sub classes. Therefore, a subclass is a specialized version of a
superclass.
To
inherit a class, we simply incorporate the definition of one class into another
by using the
extends keyword.
The
general form of a subclass declaration is:
class
subclass-name extends super class-name
{
/*body of class*/ }
We
can specify only one super class for any subclass.
This
is because Java does not support multiple inheritance.
Comments
Post a Comment