0% found this document useful (0 votes)
14 views15 pages

Unit 4 (A)

unit

Uploaded by

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

Unit 4 (A)

unit

Uploaded by

vishal2021123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

JAVA

UNIT 4(A)
Inheritance
• Inheritance is the mechanism in java by which one
class is allow to inherit the features(fields and
methods) of another class.
• 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 the parent
class.
• Moreover, you can add new methods and fields in
your current class also.
Why use inheritance in java
• For Method Overriding (so runtime
polymorphism can be achieved).
• For Code Reusability.
How to use inheritance
The keyword used for inheritance is extends.
Inheritance: Sample program
Types of inheritance
• On the basis of class, there can be three types
of inheritance in java: single, multilevel and
hierarchical.
• In java programming, multiple and hybrid
inheritance is supported through interface
only. We will learn about interfaces later.
Types of inheritance
Single Inheritance
Multilevel Inheritance
Hierarchical Inheritance
Super keyword
• The super keyword in java is a reference
variable that is used to refer parent class
objects.
• The keyword “super” came into the picture
with the concept of Inheritance.
Use of super
1) To access the data members of parent class
when both parent and child class have member
with same name
2) To access the method of parent class when
child class has overridden that method.
3) To access the parent class constructor.
To access the variables of parent class
• When you have a variable in child class which
is already present in the parent class then in
order to access the variable of parent class,
you need to use the super keyword.
with super

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy