inheritance in java
DESCRIPTION
powerpoint presentation on inheritance in javaTRANSCRIPT
![Page 1: Inheritance in Java](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d0871a28ab9b0292d2c5/html5/thumbnails/1.jpg)
![Page 2: Inheritance in Java](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d0871a28ab9b0292d2c5/html5/thumbnails/2.jpg)
INHERITANCE
![Page 3: Inheritance in Java](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d0871a28ab9b0292d2c5/html5/thumbnails/3.jpg)
The word inheritance refers to the act
of inheriting material or immaterial possessions by succession .
materialimmaterial
![Page 4: Inheritance in Java](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d0871a28ab9b0292d2c5/html5/thumbnails/4.jpg)
Inheritance in java
• Inheritance is a basic concept in Object Oriented Programming .• Inheritance in java is a mechanism in which one class of objects acquires all the properties and behaviors of a parent class.• represents the IS-A / HAS-A relationship .
![Page 5: Inheritance in Java](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d0871a28ab9b0292d2c5/html5/thumbnails/5.jpg)
terms
•Superclass/base class/parent class : The class from which another class is derived .
•Subclass/derived class/child class : class that is derived from another class .
![Page 6: Inheritance in Java](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d0871a28ab9b0292d2c5/html5/thumbnails/6.jpg)
syntaxInheritance can be implemented
using the keyword extend .
class subclass_name extends superclass_name { //methods and fields }
![Page 7: Inheritance in Java](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d0871a28ab9b0292d2c5/html5/thumbnails/7.jpg)
superclass : employeesubclass : programmerrelation : IS A
programmer IS A employee .
example
![Page 8: Inheritance in Java](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d0871a28ab9b0292d2c5/html5/thumbnails/8.jpg)
source codeclass employee{ float salary=40000; }
class programmer extends Employee{ int bonus=10000; public static void main(String args[]) { programmer p=new programmer(); system.out.println(“programmer salary is :"+p.salary); system.out.println(“ponus of Programmer is:"+p.bonus); } }
![Page 9: Inheritance in Java](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d0871a28ab9b0292d2c5/html5/thumbnails/9.jpg)
outputprogrammer salary is : 40000.0 bonus of programmer is : 10000
![Page 10: Inheritance in Java](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d0871a28ab9b0292d2c5/html5/thumbnails/10.jpg)
types1.Single
inheritance .2.Multiple
inheritance .3.Multilevel
inheritance .4.Hierarchical inheritance
.5.Hybrid inheritance
.
![Page 11: Inheritance in Java](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d0871a28ab9b0292d2c5/html5/thumbnails/11.jpg)
Single inheritance
A single class is inherited from a single baseclass
![Page 12: Inheritance in Java](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d0871a28ab9b0292d2c5/html5/thumbnails/12.jpg)
example
![Page 13: Inheritance in Java](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d0871a28ab9b0292d2c5/html5/thumbnails/13.jpg)
Multiple inheritanceA single class is
inherited from a more than one baseclasses.
Java does not support multiple inheritance .
That is why java is said to be simple .
![Page 14: Inheritance in Java](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d0871a28ab9b0292d2c5/html5/thumbnails/14.jpg)
Multilevel
inheritance
A derived class acts as baseclass for another class .
![Page 15: Inheritance in Java](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d0871a28ab9b0292d2c5/html5/thumbnails/15.jpg)
example
![Page 16: Inheritance in Java](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d0871a28ab9b0292d2c5/html5/thumbnails/16.jpg)
Hierarchical inheritance
More than one class is inherited from a single baseclass
![Page 17: Inheritance in Java](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d0871a28ab9b0292d2c5/html5/thumbnails/17.jpg)
example
![Page 18: Inheritance in Java](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d0871a28ab9b0292d2c5/html5/thumbnails/18.jpg)
![Page 19: Inheritance in Java](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d0871a28ab9b0292d2c5/html5/thumbnails/19.jpg)
hybrid inheritance
a combination of single and multiple
inheritance
![Page 20: Inheritance in Java](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d0871a28ab9b0292d2c5/html5/thumbnails/20.jpg)
advantages•Code reusability – object of a derived class can also access the field of its base class .•Method overriding – we can define a same method in a derived class without altering the function in base class .
![Page 21: Inheritance in Java](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d0871a28ab9b0292d2c5/html5/thumbnails/21.jpg)