INHERITANCE
Inheritance is as important characteristic of Object-oriented programming by which we can define a new class from an extends class in such a way that the new class will acquire all the public and protected properties of extends class.The new class can also add their properties, the extended class known as the superclass or parent class, and the new class
known as subclass and child class.
Inheritance
provides the facility of code reusability if you use inheritance then the program
flow is generic to specify.
Note: java only support a public inheritance that means the visibility mode of the inheritance properties
into sub-class, public properties of the superclass become public properties
of sub-class and protected properties of superclass become protected
properties sub-class.
There are two steps to make a program using inheritance
- Superclass definitions:- Superclass definitions is same as normal class definitions in which we have to declared and define all properties of the class also have specific there visibility mode.
- Sub-class definitions:-In we have to specify the superclass with help of extends keyword.
There are five types of
Inheritance in java.
· Multiple Inheritance
· Hierarchical Inheritance
· Multilevel Inheritance
· Hybrid Inheritance
Videos Link for program:- coming soon.
SUPER KEYWORD
The super keyword is a special type of keyword which may be used in following way according to our requirement
- To access the instance variable superclass
- To access the member method of the superclass
- To access the constructor of the superclass
To access the instance variable superclass
When the name of an instance variable of a superclass and a subclass is the same then to access the instance variable of superclass we must have to use the “super” keyword.
Example.
To access the member method of super class
When the name of a method of a super class and a sub class is same then to access the method of super class we have to use “super” keyword
Example.
To access
the constructor of superclass.
No comments:
Post a Comment