Professional Documents
Culture Documents
Inheritance: Class Extends
Inheritance: Class Extends
Concept
i) Inheritance is based on the idea of reusability.
ii) This means that the features of an existing class are reused and new features are added to
it.
iii) The existing class undergoes no modifications (i.e. it remains unchanged), it is just
extended to form a new class.
Order of Invocation:
When a subclass is instantiated, the object will begin with an invocation of the constructor in
the base class and initialize downwards through constructors in each subclass till it reaches
the final subclass constructor.
Method Overriding
It is a concept which occurs when an instance method in a subclass hides or overrides an
inherited method of the superclass due to similar declarations.
Overridden methods are methods that are redefined within an inherited class or subclass.
An overridden super class method can be invoked in a subclass using the keyword super as:
super . overriddenMethod( ) ;
Abstract Classes
i) An abstract class defines a structure of given abstraction without any implementation.
ii) In Java, an abstract class is a special type of superclass that is specified by using the
abstract keyword as:
abstract class < classname >
{ ……. }
iii) Abstract classes cannot be instantiated, as they are defined solely for the purpose of
extension (inheritance) by other classes.
Abstract Methods
i) It is an overridden method which is declared with the abstract modifier in an abstract
super class, but implemented
specifically in a subclass.
Declaration Syntax:
abstract type <methodname> ([ parameter–list ]) ;
Polymorphism: It is the capability of an action or method to do different things based on the
object it is acting upon.
Compile Time Run Time
Class Vs Interface:
i) A class consists of instance variables and methods definitions while an interface consists
of final constants and method declarations.
ii) A class can be instantiated using the new operator while an interface cannot be
instantiated as they are abstract in nature.
Abstract Class Vs Interface:
i) An abstract class is defined using abstract keyword while an interface is specified using
keyword interface.
ii) An abstract class is implemented using extends keyword while an interface is
implemented using keyword