Inheritance in Java
Inheritance in Java
Inheritance in Java
com
http://www.javatpoint.com/inheritance-in-java
Inheritance in Java
next prev
Inheritance in java is a mechanism in which one object acquires all the properties and behaviors of parent
object.
The idea behind inheritance in java is that you can create new classes that are built upon existing classes.
When you inherit from an existing class, you can reuse methods and fields of parent class, and you can add
new methods and fields also.
Inheritance represents the IS-A relationship, also known as parent-child relationship.
8.
9.
10. }
11. }
Test it Now
Programmer salary is:40000.0
Bonus of programmer is:10000
1/3
In the above example, Programmer object can access the field of own class as well as of Employee class i.e.
code reusability.
2/3
C obj=new C();
obj.msg();
11. }
12. }
Test it Now
Compile Time Error
Next TopicAggregation in java (HAS-A)
prev next
3/3