Object Orinted programming
4 Inheritance
Inheritance is the producer by which one object acquries all the proprties and behavior of a parent object.It is Inheritance the properties of parent class into chlid class.
It is always better pre existing rather than creating all over agian .this is done using Inheritance. inheritance provide us alway using which we can use pre-existing our current programming/application.
it is with inheritance one class derive the properties of another class.
java:- By using extends Keyword to achive inheritance
Advantage of Inheritance
- Inheritance promotes reusability. When a class inherits or derives another class, it can access all the functionality of inherited class.
- Reusability enhanced reliability. The base class code will be already tested and debugged.
- Inheritance makes the sub classes follow a standard interface.
- Inheritance helps to reduce code redundancy and supports code extensibility.
- Inheritance facilitates creation of class libraries.
DisAdvantage of Inheritance
- Inherited functions work slower than normal function as there is indirection.
- Improper use of inheritance may lead to wrong solutions.
- Often, data members in the base class are left unused which may lead to memory wastage.
- Inheritance increases the coupling between base class and derived class. A change in base class will affect all the child classes.
Object
Type of Inheritance:--------- 5
- 1.Single Inheritance
- 2.Multilevel Inheritance
- 3.Hierachical Inheritance
- 4. Multiple Inheritance
- 5.Hybrid Inheritance
1. Single Inheritance
When one base class is being to derived class (Single) is called as Single inheritance.
Object
how to calcaulate area of reactangle by using single Inheritance ?
Single Inheritance
{
{
CONTENT FIR TAB 4
Input
enter the lenght =10
enter the breath =10
output
Area of reactangle = 100.
No comments:
Post a Comment