SlideShare a Scribd company logo
JAVA
Inheritance
Prepared by
Miss. Arati A. Gadgil
2
Inheritance
Inheritance enables you to create a class that is similar to a previously
defined class, but one that still has some of its own properties, known as
code reusability.
When a class “B” inherits from or extends another class “A” then, A is
called the superclass of B, and B the subclass of A.
All the public and protected members of the superclass are available to
the subclass.
We can control the level of inheritance with the public, private, and
protected keywords.
Any class that is not explicitly declared as final can be extended.
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.
Syntax
For one class to be a subclass of another, we use the extends keyword:
Class Marks
{
----------;
----------;
}
Class Result extends Marks
{
----------;
----------;
}
Super class
Sub class
Method overriding
Overriding refers a method in a subclass that has the same name, same
argument, and return type of a method in the superclass.
Implementation of this method in the subclass replaced the
implementation of the method in the superclass.
Example
Class Marks
{
public void display();
}
Class Result extends Marks
{
public void display();
}
5
Polymorphism
By using polymorphism, we can create new objects that perform the
same functions as the base object but which perform one or more
of these functions in a different way.
For example, you may have a shape object that draws a circle on the
screen. By using polymorphism, we can create a shape object that draws
a rectangle instead.
We can do this by creating a new version of the method that draws the
shape on the screen. Both the old circle-drawing and the new rectangle-
drawing method have the same name (such as DrawShape()) but drawing
in a different way.
6
Inheritance hierarchies
we may classify inheritance relationship into different categories
Specialization: the derived class is a special case of its base class, it
specializes its behavior and it is a subtype.
Generalization: the base class is obtained as result of finding common
behavior in different classes that become its children;
these derived classes override some of the methods in
the base class.
Specification: the base class defines some behavior that it is only
implemented in the derived class.
Extension: the derived class adds some behavior but does not
change the inherited behavior.
7
Combination: the derived class inherits some behavior from more
than one base class (multiple inheritance).
Construction: the derived class uses the behavior implemented in
the base class but it is not a subtype.
Limitation: the derived class restricts the use of some of the
behavior implemented in the base class.
Variance: the derived and base class are variants one of the other
and the relation class/subclass is arbitrary.
first two out of eight are common . The last three are not recommended.
On the other hand, while the origin and intent is different in all of the
different inheritance kinds, the result of applying them may be
indistinguishable.
8
In a generalization process the derived classes exist before and the base
class is obtained by realizing the commonalities in them.
In the specialization process the base class is ``broken down'' into
different derived classes. Inheritance hierarchies allow to manage a
system complexity.
We want all branches in an inheritance hierarchy to be disjoint and
balanced.
Disjoint means that any given object may not be an instance of two of
the subclasses found at the same level of the hierarchy.
By balanced we mean that two subclasses should represent comparable
sized sets of objects, having a very general class and a very particular
one at the same level of the hierarchy is not a good idea.
9
Inheritance can also be classified into static or dynamic.
In a static specialization an object belonging to a particular level of the
hierarchy is not intended to change in run-time from one subclass to
another.
In a dynamic specialization the belonging of the object to a particular
subclass depends on its state and therefore can change on run-time.
Dynamic inheritance, although theoretically correct, introduces many
practical problems and is often substituted, following
the delegation principle, by an association and a static inheritance.
10
Abstract classes
The class is called abstract if class contains one or more abstract method
Abstract classes must be inherited ,but not be instantiated.
It is not required that a subclass implement every abstract method in an
abstract superclass.
However, if all abstract methods are not implemented in the subclass, the
subclass must be declared abstract.
classes with all abstract methods are almost exactly like interfaces
11
Casting
Converting one type of value to another is called as Type Casting.
You can cast an instance of a child class to its parent class. Casting an
object of child class to a parent class is called upcasting.
Casting an object of a parent class to its child class is
called downcasting.
12
Types of Inheritance
1.Single
Class A
Class B
2.Multilevel
Class A
Class B
Class C
3.Multiple
Class A Class B
Class C
Multiple inheritance is not supported by java.
Consider A, B and C are three classes. The C class inherits A and B
classes. If A and B classes have same method and you call it from child
class object, there will be ambiguity to call method of A or B class.
13
The super keyword
Super keyword is used to differentiate the members of superclass from
the members of subclass, if they have same names.
It is used to call the superclass constructor from subclass constructor.
Final method and class
If any method is declared as a final then we can not override that method
If any class is declared as final then we can not extends that class.
Java Inner Class
Java inner class or nested class is a class i.e. declared inside
the class or interface.
Syntax of Inner class
class Java_Outer_class
{
//code
class Java_Inner_class
{
//code
}
}
Nested class
Non static
nested
Static nested
Member
class
Local
class
Anonymous
class
Types of Nested classes
•There are two types of nested classes non-static and static nested
classes.
•The non-static nested classes are also known as inner classes.
Non-static nested class(inner class)
a)Member inner class
A class created within class and outside method.
b)Annomynous inner class
A class created for implementing interface or
extending class. Its name is decided by the java compiler.
c)Local inner class
A class created within method
Static nested class
A static class created within class
class outer
{ int no;
outer()
{ no=10; }
class inner
{
void show()
{
System.out.println("no="+no);
}
}
public static void main(String args[])
{
outer obj1=new outer();
outer.inner obj2=obj1.new inner();
obj2.show();
}
}
Garbage collection
Since objects are dynamically allocated by using the new operator.
Java handles deallocation automatically. The technique that
accomplishes this is called garbage collection.
It works like this:
when no references to an object to exist, that object is assumed to
be no longer needed, and the memory occupied by the object can be
reclaimed.
Garbage collection only occurs sporadically (if at all) during the
execution of your program. It will not occur simply because one or
more objects exist that are no longer used.
 Furthermore, different java run-time implementations will take
varying approaches to garbage collection, but for the most part, you
should not have to think about it while writing your programs
The finalize () Method
 Sometimes an object will need to perform some action when it is 
destroyed. 
For example, if an object is holding some non-java resource such as a 
file handle or window character font, then you might want to make sure 
these resources are freed before an object is destroyed. 
To handle such situations, java provides a mechanism called 
finalization. By using finalization, you can define specific actions that 
will occur when an object is just about to be reclaimed by the garbage 
collector.
•To add a finalizer to a class, you simply define 
the finalize() method. 
•The java run time calls that method whenever it is about to recycle 
an object of that class. 
•Inside the finalize() method you will specify those actions that 
must be performed before an object is destroyed. 
•The garbage collector runs periodically, checking for objects that 
are no longer referenced by any running state or indirectly through 
other referenced objects.
• Right before an asset is freed, the java run time calls 
the finalize()method on the object.
The finalize() method has this general form:
 
            protected void finalize()
            {
             // finalization code here
            }
Thank You
22
Ad

More Related Content

What's hot (20)

Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
COMSATS Institute of Information Technology
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
Tareq Hasan
 
Abstract class in java
Abstract class in javaAbstract class in java
Abstract class in java
Lovely Professional University
 
Inheritance In Java
Inheritance In JavaInheritance In Java
Inheritance In Java
Arnab Bhaumik
 
Encapsulation C++
Encapsulation C++Encapsulation C++
Encapsulation C++
Hashim Hashim
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
HarshitaAshwani
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
Elizabeth alexander
 
WHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVAWHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVA
sivasundari6
 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in java
Hitesh Kumar
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
Pooja Jaiswal
 
C# Inheritance
C# InheritanceC# Inheritance
C# Inheritance
Prem Kumar Badri
 
Java interface
Java interfaceJava interface
Java interface
Md. Tanvir Hossain
 
Inheritance In Java
Inheritance In JavaInheritance In Java
Inheritance In Java
Darpan Chelani
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Tech_MX
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
Laxman Puri
 
Abstraction java
Abstraction javaAbstraction java
Abstraction java
MahinImran
 
Member Function in C++
Member Function in C++ Member Function in C++
Member Function in C++
NikitaKaur10
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Paumil Patel
 
Abstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaAbstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core Java
MOHIT AGARWAL
 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
Tamanna Akter
 

Viewers also liked (20)

Inheritance
InheritanceInheritance
Inheritance
Selvin Josy Bai Somu
 
Java Inheritance
Java InheritanceJava Inheritance
Java Inheritance
Rosie Jane Enomar
 
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
cprogrammings
 
inheritance c++
inheritance c++inheritance c++
inheritance c++
Muraleedhar Sundararajan
 
Inheritance chepter 7
Inheritance chepter 7Inheritance chepter 7
Inheritance chepter 7
kamal kotecha
 
C++ Inheritance
C++ InheritanceC++ Inheritance
C++ Inheritance
Jussi Pohjolainen
 
itft-Inheritance in java
itft-Inheritance in javaitft-Inheritance in java
itft-Inheritance in java
Atul Sehdev
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
BHUVIJAYAVELU
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vineeta Garg
 
Java Basics
Java BasicsJava Basics
Java Basics
shivamgarg_nitj
 
Packages and interfaces
Packages and interfacesPackages and interfaces
Packages and interfaces
vanithaRamasamy
 
Java packages
Java packagesJava packages
Java packages
Raja Sekhar
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
Raffaele Doti
 
Inheritance
InheritanceInheritance
Inheritance
Daman Toor
 
20 online promotion tips for seafood industry to try right now
20 online promotion tips for seafood industry to try right now20 online promotion tips for seafood industry to try right now
20 online promotion tips for seafood industry to try right now
Social Bubble
 
Creación de Bases de Datos en SQL Server
Creación de Bases de Datos en SQL ServerCreación de Bases de Datos en SQL Server
Creación de Bases de Datos en SQL Server
Pedrangas Pedrangas
 
"Creación de bases de datos en SQL Server"
"Creación de bases de datos en SQL Server" "Creación de bases de datos en SQL Server"
"Creación de bases de datos en SQL Server"
pacovar
 
Java Inheritance
Java InheritanceJava Inheritance
Java Inheritance
Kapish Joshi
 
object oriented programming(syed munib ali 11b-023-bs)
object oriented programming(syed munib ali 11b-023-bs)object oriented programming(syed munib ali 11b-023-bs)
object oriented programming(syed munib ali 11b-023-bs)
munibali55
 
Java kid8x11
Java kid8x11Java kid8x11
Java kid8x11
Davidson Gilbert
 
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
cprogrammings
 
Inheritance chepter 7
Inheritance chepter 7Inheritance chepter 7
Inheritance chepter 7
kamal kotecha
 
itft-Inheritance in java
itft-Inheritance in javaitft-Inheritance in java
itft-Inheritance in java
Atul Sehdev
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vineeta Garg
 
20 online promotion tips for seafood industry to try right now
20 online promotion tips for seafood industry to try right now20 online promotion tips for seafood industry to try right now
20 online promotion tips for seafood industry to try right now
Social Bubble
 
Creación de Bases de Datos en SQL Server
Creación de Bases de Datos en SQL ServerCreación de Bases de Datos en SQL Server
Creación de Bases de Datos en SQL Server
Pedrangas Pedrangas
 
"Creación de bases de datos en SQL Server"
"Creación de bases de datos en SQL Server" "Creación de bases de datos en SQL Server"
"Creación de bases de datos en SQL Server"
pacovar
 
object oriented programming(syed munib ali 11b-023-bs)
object oriented programming(syed munib ali 11b-023-bs)object oriented programming(syed munib ali 11b-023-bs)
object oriented programming(syed munib ali 11b-023-bs)
munibali55
 
Ad

Similar to Java inheritance (20)

Unit 3 Java
Unit 3 JavaUnit 3 Java
Unit 3 Java
arnold 7490
 
Inheritance ppt
Inheritance pptInheritance ppt
Inheritance ppt
Nivegeetha
 
Lecture 10
Lecture 10Lecture 10
Lecture 10
Debasish Pratihari
 
Inheritance in java.pptx_20241025_101324_0000.pptx.pptx
Inheritance in java.pptx_20241025_101324_0000.pptx.pptxInheritance in java.pptx_20241025_101324_0000.pptx.pptx
Inheritance in java.pptx_20241025_101324_0000.pptx.pptx
saurabhthege
 
Chapter 9 java
Chapter 9 javaChapter 9 java
Chapter 9 java
Ahmad sohail Kakar
 
java_vyshali.pdf
java_vyshali.pdfjava_vyshali.pdf
java_vyshali.pdf
Vyshali6
 
Java(inheritance)
Java(inheritance)Java(inheritance)
Java(inheritance)
Pooja Bhojwani
 
Chap3 inheritance
Chap3 inheritanceChap3 inheritance
Chap3 inheritance
raksharao
 
Inheritance
Inheritance Inheritance
Inheritance
sourav verma
 
Inheritance in Java - An Introduction & types
Inheritance in Java - An Introduction & typesInheritance in Java - An Introduction & types
Inheritance in Java - An Introduction & types
VijethaChandran
 
Inheritance and Polymorphism
Inheritance and PolymorphismInheritance and Polymorphism
Inheritance and Polymorphism
KartikKapgate
 
Object Oriented Programming - 7.1. Inheritance
Object Oriented Programming - 7.1. InheritanceObject Oriented Programming - 7.1. Inheritance
Object Oriented Programming - 7.1. Inheritance
AndiNurkholis1
 
9781439035665 ppt ch10
9781439035665 ppt ch109781439035665 ppt ch10
9781439035665 ppt ch10
Terry Yoast
 
TYPES OF INHERITANCE CONCEPT IN C++.pptx
TYPES OF INHERITANCE CONCEPT IN C++.pptxTYPES OF INHERITANCE CONCEPT IN C++.pptx
TYPES OF INHERITANCE CONCEPT IN C++.pptx
SPECIALISESPECIALISE
 
Ganesh groups
Ganesh groupsGanesh groups
Ganesh groups
Ganesh Amirineni
 
JAVA UNIT 2 BCA students' notes IPU university
JAVA UNIT 2 BCA students' notes IPU universityJAVA UNIT 2 BCA students' notes IPU university
JAVA UNIT 2 BCA students' notes IPU university
n32310997
 
PPT Lecture-1.4.pptx
PPT Lecture-1.4.pptxPPT Lecture-1.4.pptx
PPT Lecture-1.4.pptx
HimanshuPandey957216
 
Core java by amit
Core java by amitCore java by amit
Core java by amit
Thakur Amit Tomer
 
lecture 6.pdf
lecture 6.pdflecture 6.pdf
lecture 6.pdf
WaqarRaj1
 
Java basics
Java basicsJava basics
Java basics
Shivanshu Purwar
 
Inheritance ppt
Inheritance pptInheritance ppt
Inheritance ppt
Nivegeetha
 
Inheritance in java.pptx_20241025_101324_0000.pptx.pptx
Inheritance in java.pptx_20241025_101324_0000.pptx.pptxInheritance in java.pptx_20241025_101324_0000.pptx.pptx
Inheritance in java.pptx_20241025_101324_0000.pptx.pptx
saurabhthege
 
java_vyshali.pdf
java_vyshali.pdfjava_vyshali.pdf
java_vyshali.pdf
Vyshali6
 
Chap3 inheritance
Chap3 inheritanceChap3 inheritance
Chap3 inheritance
raksharao
 
Inheritance in Java - An Introduction & types
Inheritance in Java - An Introduction & typesInheritance in Java - An Introduction & types
Inheritance in Java - An Introduction & types
VijethaChandran
 
Inheritance and Polymorphism
Inheritance and PolymorphismInheritance and Polymorphism
Inheritance and Polymorphism
KartikKapgate
 
Object Oriented Programming - 7.1. Inheritance
Object Oriented Programming - 7.1. InheritanceObject Oriented Programming - 7.1. Inheritance
Object Oriented Programming - 7.1. Inheritance
AndiNurkholis1
 
9781439035665 ppt ch10
9781439035665 ppt ch109781439035665 ppt ch10
9781439035665 ppt ch10
Terry Yoast
 
TYPES OF INHERITANCE CONCEPT IN C++.pptx
TYPES OF INHERITANCE CONCEPT IN C++.pptxTYPES OF INHERITANCE CONCEPT IN C++.pptx
TYPES OF INHERITANCE CONCEPT IN C++.pptx
SPECIALISESPECIALISE
 
JAVA UNIT 2 BCA students' notes IPU university
JAVA UNIT 2 BCA students' notes IPU universityJAVA UNIT 2 BCA students' notes IPU university
JAVA UNIT 2 BCA students' notes IPU university
n32310997
 
lecture 6.pdf
lecture 6.pdflecture 6.pdf
lecture 6.pdf
WaqarRaj1
 
Ad

More from Arati Gadgil (16)

Java adapter
Java adapterJava adapter
Java adapter
Arati Gadgil
 
Java swing
Java swingJava swing
Java swing
Arati Gadgil
 
Java applet
Java appletJava applet
Java applet
Arati Gadgil
 
Java layoutmanager
Java layoutmanagerJava layoutmanager
Java layoutmanager
Arati Gadgil
 
Java awt
Java awtJava awt
Java awt
Arati Gadgil
 
Java stream
Java streamJava stream
Java stream
Arati Gadgil
 
Java thread
Java threadJava thread
Java thread
Arati Gadgil
 
Java networking
Java networkingJava networking
Java networking
Arati Gadgil
 
Java jdbc
Java jdbcJava jdbc
Java jdbc
Arati Gadgil
 
Java package
Java packageJava package
Java package
Arati Gadgil
 
Java interface
Java interfaceJava interface
Java interface
Arati Gadgil
 
Java eventhandling
Java eventhandlingJava eventhandling
Java eventhandling
Arati Gadgil
 
Java exception
Java exception Java exception
Java exception
Arati Gadgil
 
Java collection
Java collectionJava collection
Java collection
Arati Gadgil
 
Java class
Java classJava class
Java class
Arati Gadgil
 
Java basic
Java basicJava basic
Java basic
Arati Gadgil
 

Recently uploaded (20)

History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
The History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptxThe History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living WorkshopLDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDM Mia eStudios
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast BrooklynBridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
i4jd41bk
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18
Celine George
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE  BY sweety Tamanna Mahapatra MSc PediatricAPGAR SCORE  BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
SweetytamannaMohapat
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living WorkshopLDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDM Mia eStudios
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast BrooklynBridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
i4jd41bk
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18
Celine George
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE  BY sweety Tamanna Mahapatra MSc PediatricAPGAR SCORE  BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
SweetytamannaMohapat
 

Java inheritance

  • 2. 2 Inheritance Inheritance enables you to create a class that is similar to a previously defined class, but one that still has some of its own properties, known as code reusability. When a class “B” inherits from or extends another class “A” then, A is called the superclass of B, and B the subclass of A. All the public and protected members of the superclass are available to the subclass. We can control the level of inheritance with the public, private, and protected keywords. Any class that is not explicitly declared as final can be extended. 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.
  • 3. Syntax For one class to be a subclass of another, we use the extends keyword: Class Marks { ----------; ----------; } Class Result extends Marks { ----------; ----------; } Super class Sub class
  • 4. Method overriding Overriding refers a method in a subclass that has the same name, same argument, and return type of a method in the superclass. Implementation of this method in the subclass replaced the implementation of the method in the superclass. Example Class Marks { public void display(); } Class Result extends Marks { public void display(); }
  • 5. 5 Polymorphism By using polymorphism, we can create new objects that perform the same functions as the base object but which perform one or more of these functions in a different way. For example, you may have a shape object that draws a circle on the screen. By using polymorphism, we can create a shape object that draws a rectangle instead. We can do this by creating a new version of the method that draws the shape on the screen. Both the old circle-drawing and the new rectangle- drawing method have the same name (such as DrawShape()) but drawing in a different way.
  • 6. 6 Inheritance hierarchies we may classify inheritance relationship into different categories Specialization: the derived class is a special case of its base class, it specializes its behavior and it is a subtype. Generalization: the base class is obtained as result of finding common behavior in different classes that become its children; these derived classes override some of the methods in the base class. Specification: the base class defines some behavior that it is only implemented in the derived class. Extension: the derived class adds some behavior but does not change the inherited behavior.
  • 7. 7 Combination: the derived class inherits some behavior from more than one base class (multiple inheritance). Construction: the derived class uses the behavior implemented in the base class but it is not a subtype. Limitation: the derived class restricts the use of some of the behavior implemented in the base class. Variance: the derived and base class are variants one of the other and the relation class/subclass is arbitrary. first two out of eight are common . The last three are not recommended. On the other hand, while the origin and intent is different in all of the different inheritance kinds, the result of applying them may be indistinguishable.
  • 8. 8 In a generalization process the derived classes exist before and the base class is obtained by realizing the commonalities in them. In the specialization process the base class is ``broken down'' into different derived classes. Inheritance hierarchies allow to manage a system complexity. We want all branches in an inheritance hierarchy to be disjoint and balanced. Disjoint means that any given object may not be an instance of two of the subclasses found at the same level of the hierarchy. By balanced we mean that two subclasses should represent comparable sized sets of objects, having a very general class and a very particular one at the same level of the hierarchy is not a good idea.
  • 9. 9 Inheritance can also be classified into static or dynamic. In a static specialization an object belonging to a particular level of the hierarchy is not intended to change in run-time from one subclass to another. In a dynamic specialization the belonging of the object to a particular subclass depends on its state and therefore can change on run-time. Dynamic inheritance, although theoretically correct, introduces many practical problems and is often substituted, following the delegation principle, by an association and a static inheritance.
  • 10. 10 Abstract classes The class is called abstract if class contains one or more abstract method Abstract classes must be inherited ,but not be instantiated. It is not required that a subclass implement every abstract method in an abstract superclass. However, if all abstract methods are not implemented in the subclass, the subclass must be declared abstract. classes with all abstract methods are almost exactly like interfaces
  • 11. 11 Casting Converting one type of value to another is called as Type Casting. You can cast an instance of a child class to its parent class. Casting an object of child class to a parent class is called upcasting. Casting an object of a parent class to its child class is called downcasting.
  • 12. 12 Types of Inheritance 1.Single Class A Class B 2.Multilevel Class A Class B Class C 3.Multiple Class A Class B Class C Multiple inheritance is not supported by java. Consider A, B and C are three classes. The C class inherits A and B classes. If A and B classes have same method and you call it from child class object, there will be ambiguity to call method of A or B class.
  • 13. 13 The super keyword Super keyword is used to differentiate the members of superclass from the members of subclass, if they have same names. It is used to call the superclass constructor from subclass constructor. Final method and class If any method is declared as a final then we can not override that method If any class is declared as final then we can not extends that class.
  • 14. Java Inner Class Java inner class or nested class is a class i.e. declared inside the class or interface. Syntax of Inner class class Java_Outer_class { //code class Java_Inner_class { //code } }
  • 15. Nested class Non static nested Static nested Member class Local class Anonymous class
  • 16. Types of Nested classes •There are two types of nested classes non-static and static nested classes. •The non-static nested classes are also known as inner classes. Non-static nested class(inner class) a)Member inner class A class created within class and outside method. b)Annomynous inner class A class created for implementing interface or extending class. Its name is decided by the java compiler. c)Local inner class A class created within method Static nested class A static class created within class
  • 17. class outer { int no; outer() { no=10; } class inner { void show() { System.out.println("no="+no); } } public static void main(String args[]) { outer obj1=new outer(); outer.inner obj2=obj1.new inner(); obj2.show(); } }
  • 18. Garbage collection Since objects are dynamically allocated by using the new operator. Java handles deallocation automatically. The technique that accomplishes this is called garbage collection. It works like this: when no references to an object to exist, that object is assumed to be no longer needed, and the memory occupied by the object can be reclaimed. Garbage collection only occurs sporadically (if at all) during the execution of your program. It will not occur simply because one or more objects exist that are no longer used.  Furthermore, different java run-time implementations will take varying approaches to garbage collection, but for the most part, you should not have to think about it while writing your programs
  • 19. The finalize () Method  Sometimes an object will need to perform some action when it is  destroyed.  For example, if an object is holding some non-java resource such as a  file handle or window character font, then you might want to make sure  these resources are freed before an object is destroyed.  To handle such situations, java provides a mechanism called  finalization. By using finalization, you can define specific actions that  will occur when an object is just about to be reclaimed by the garbage  collector.
  翻译: