0% found this document useful (0 votes)
8 views4 pages

7 Inheritance

Inheritance in Java is a key concept of Object-Oriented Programming (OOP) that allows one class to acquire properties and behaviors from another class, establishing a father-child relationship. The class that inherits is called the subclass, while the class being inherited from is the superclass, and this is achieved using the 'extends' keyword. Java supports single, multilevel, and hierarchical inheritance, but does not support multiple or hybrid inheritance.

Uploaded by

jahnavi garg
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

7 Inheritance

Inheritance in Java is a key concept of Object-Oriented Programming (OOP) that allows one class to acquire properties and behaviors from another class, establishing a father-child relationship. The class that inherits is called the subclass, while the class being inherited from is the superclass, and this is achieved using the 'extends' keyword. Java supports single, multilevel, and hierarchical inheritance, but does not support multiple or hybrid inheritance.

Uploaded by

jahnavi garg
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Inheritance in java

inheritance is an important of concept of OOP

Inheritance is a process to make a father-child relationship through which


one class acquires properties and behaviour(methods & attributes) of other
class.

Process for achieving Inheritance


1.​ the information is made manageable in a hierarchical order. (from a
father to its child)
2.​ The class which inherits the properties of other is known as subclass
(derived class, child class)
3.​ the class whose properties are inherited is known as superclass (base
class, parent class)
4.​ It can be achieved by extends keyword

This kind of relationship is also called is-A relationship

Let see some example


1.​ We have class calculator
2.​ Suppose some one created this calculator class and we need to build a
Advance calculator which will perform some more operations
3.​ If this Calculator is used by other programmers.(suppose if this
calculator class object is used in multiple main method/Driver classes)
4.​ We will not try to directly change this Calculator class.
5.​ What we will do,we will extend the existing functionality of this class by
inheriting it or extending it.

●​ Now lets us make use of this Calculator class

1.​ The Calculator class has three methods add (2 parameters) ,add(3
parameters) and sub only.
2.​ AdvCalculator class has only two method mul and div but it will inherit
other three methods add,add and sub from it’s parent class Calculator
Let us Analyse
1.​ Calculator is super/parent/base class and AdvCalculator is
child/derived class.
2.​ AdvCalcultor is-A Calculator.
3.​ Calculator has 3 methods while AdvCalcultor has 5 methods, 2 of its
own and 3 inherited.
4.​ Properties can also be inherited.
5.​ Only private properties and methods are not inherited.
Types of Java Inheritance
1.​ There are 3 types of inheritances Single, Multilevel, and
Hierarchical supported in java
2.​ Java does not support Multiple and Hybrid inheritance.

You might also like