SlideShare a Scribd company logo
Amar Jukuntla, M.Tech.,
Assistant Professor,
Department Computer Science and Engineering
VFSTR Deemed to Be University,
Vadlamudi
1
§ Inheritance-Basics
§ Member Access Rules
§ Super
§ Final
§ The Object Class
§ Forms of inheritance
§ Benefits of Inheritance
§ Cost of Inheritance
§ Polymorphism
§ Method Overriding
§ Abstract Classes
2
§ Inheritance is the process of deriving a new class based on already
existing class.
§ The newly derived class is called “subclass” or “childclass”. The
existing class is called “superclass” or “baseclass” or “parentclass”.
§ A subclass is a specialized version of its superclass. It inherits all of the
instances variables and methods defined by the “superclass” and it
adds its own elements.
§ Inheritance is the process by which one object acquires the properties
of another object.
§ Inheritance allows code defining one class to be used in other class.
§ By using “extend” keyword we can inherit a class from an existing class.
3
§ The general form of a class that inherits a super class is:
class subclass_name extends superclass_name{
//instances
//methods
//variables
//……..
}
4
§ We can specify only one superclass for any subclass that we create.
§ Java does not support the inheritance of “multiple super classes” into a single
subclass.
§ We can create hierarchy of inheritance, which a subclass becomes a superclass of
another subclass.(Hierchial Association).
5
6
Base class
class A
{
int i; // public by default
private int j; // private to A
void setij(int x, int y) {
i = x;
j = y;
}
}
Subclass
class B extends A {
int total;
void sum() {
total = i + j;
// ERROR, j is not
accessible here
}
}
Accessing
class Access {
public static void main(String args[]) {
B subOb = new B();
subOb.setij(10, 12);
subOb.sum();
System.out.println("Total is " +
subOb.total);
}
}
7
§ Public
§ Private
§ Protected
8
9
Declared As
Accessible
Public Protected Private
Class
Other Class in
the Package
Sub Class in the
Package
Sub Class
outside the
package
Other package
§Whenever a subclass needs to refer to its
immediate superclass, it can do so by use of the
keyword super.
§super has two general forms.
§The first calls the superclass’ constructor.
§The second is used to access a member of the superclass
that has been hidden by a member of a subclass.
10
A subclass can call a
constructor defined
by its superclass by
use of the following
form of super:
super(arg-list);
Base Class
class Box{
double width;
double height;
double depth;
Box(double w, double h, double d)
{
width=w;
height=h;
depth=d;
}
}
Sub Class
class BoxWeight extends Box{
double weight;
BoxWeight(double w,double h,double d,double m)
{
super(w,h,d);
weight=m;
}
}
11
The second form of super
acts somewhat like this,
except that it always refers
to the superclass of the
subclass in which it is used.
This usage has the
following general form:
super.member
Here, member can be either
a method or an instance
variable.
12
Base Class
class Box{
double width;
double height;
double depth;
double weight;
Box(double w, double h, double d)
{
width=w;
height=h;
depth=d;
}
}
Sub Class
class BoxWeight extends Box{
BoxWeight(double w,double h,double d,double m)
{
super(w,h,d);
super.weight=m;
}
}
class Box{
double width, height,depth;
Box()
{ width = 10;height = 10;depth = 10;
}
Box(double w, double h, double d)
{width=w;height=h;depth=d;
}
double vol()
{
return width*height*depth;
}
}
class BoxDemo extends Box
{
BoxDemo()
{//super(10.0,20.0,30.0);}
void display()
{ double w=super.width;double h=super.height;double d=super.depth;
System.out.println("Width:"+w+"nDepth:"+d+"nHeight:"+h+"n");
double vol=super.vol();
System.out.println("Volume of the BOX:"+vol);
}
public static void main(String args[])
{
BoxDemo bd=new BoxDemo();
bd.display();
}
}
13
§ The keyword final has three uses.
§ First, it can be used to create the equivalent of a named constant.
§ The other two uses of final apply to inheritance.
14
class A {
final void meth() {
System.out.println("This is a final method.");
}
}
class B extends A {
void meth() { // ERROR! Can't override.
System.out.println("Illegal!");
}
}
15
§Declaring a class as final implicitly declares all of its
methods as final, too.
final class A {
// ...
}
// The following class is illegal.
class B extends A { // ERROR! Can't subclass A
// ...
}
16
§ A subtype is a class that satisfies the principle of substitutability.
§ A subclass is something constructed using inheritance, whether or not it satisfies the principle of substitutability.
§ The two concepts are independent. Not all subclasses are subtypes, and (at least in some languages) you can
construct subtypes that are not subclasses.
§ Substitutability is fundamental to many of the powerful software development techniques in OOP.
§ The idea is that, declared a variable in one type may hold the value of different type.
§ Substitutability can occur through use of inheritance, whether using extends, or using implements keywords.
17
§ Substitutability means, the type of the variable does not have to match with the
type of the value assigned to that variable.
§ Substitutability cannot be achieved in conventional languages in C, but can be
achieved in Object Oriented languages like Java.
§ We have already seen the concept of “Assigning a subclass object to superclass
variable or reference”. This is called substitutability. Here I am substituting the
superclass object with the object of subclass.
18
§ Specialization
§ The child class is a special case of the parent class; in other words, the child class is a subtype of the
parent class.
§ Specification
§ The parent class defines behavior that is implemented in the child class but not in the parent class.
§ Construction
§ The child class makes use of the behavior provided by the parent class, but is not a subtype of the
parent class.
§ Extension
§ The child class adds new functionality to the parent class, but does not change any inherited
behavior.
§ Limitation
§ The child class restricts the use of some of the behavior inherited from the parent class.
§ Combination
§ The child class inherits features from more than one parent class. Although multiple inheritance is not
supported directly by Java, it can be simulated in part by classes that use both inheritance and
implementation of an interface, or implement two or more interfaces
19
§ Software reusability
§ Code sharing
§ Consistency of interface
§ Software components
§ Rapid prototyping
§ Information hiding
20
§ Execution speed
§ Program size
§ Message-passing overhead
§ Program complexity
21
§Polymorphism
§ Ability to change form is known as Polymorphism.
§ Polymorphism means “many forms”.
§ Method overloading, method overriding, interfaces are the example
of Polymorphism.
§ Example:
22
23
§ A class that is declared as abstract is known as abstract class. It needs to be
extended and its method implemented. It cannot be instantiated.
§ Example: abstract class A{}
§ A method that is declared as abstract and does not have implementation is known
as abstract method.
§ Example:abstract void printStatus();//no body and abstract
24
abstract class Bike{
abstract void run();
}
class Honda4 extends Bike{
void run()
{
System.out.println("running safely..");
}
public static void main(String args[])
{
Bike obj = new Honda4();
obj.run();
}
}
25
§ There is one special class, Object, defined by Java. All other classes are subclasses
of Object.
26
§ The methods getClass( ), notify( ), notifyAll( ), and wait( ) are declared as final.
You may override the others.
§ However,notice two methods now: equals( ) and toString( ).
§ The equals( ) method compares the contents of two objects. It returns true if the
objects are equivalent, and false otherwise. The precise definition of equality can
vary, depending on the type of objects being compared.
§ The toString( ) method returns a string that contains a description of the object on
which it is called.
27

More Related Content

What's hot

SEMINAR
SEMINARSEMINAR
OOP in Java
OOP in JavaOOP in Java
OOP in Java
wiradikusuma
 
Oops
OopsOops
Oops
Prabhu R
 
concept of oops
concept of oopsconcept of oops
concept of oops
prince sharma
 
General OOP Concepts
General OOP ConceptsGeneral OOP Concepts
General OOP Concepts
Praveen M Jigajinni
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
Md.Al-imran Roton
 
Advanced OOP - Laws, Principles, Idioms
Advanced OOP - Laws, Principles, IdiomsAdvanced OOP - Laws, Principles, Idioms
Advanced OOP - Laws, Principles, Idioms
Clint Edmonson
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
Amit Soni (CTFL)
 
1 unit (oops)
1 unit (oops)1 unit (oops)
1 unit (oops)
Jay Patel
 
Oops concept in c++ unit 3 -topic 4
Oops concept in c++ unit 3 -topic 4Oops concept in c++ unit 3 -topic 4
Oops concept in c++ unit 3 -topic 4
MOHIT TOMAR
 
Oop Presentation
Oop PresentationOop Presentation
Oop Presentation
Ghaffar Khan
 
Java Object Oriented Programming
Java Object Oriented Programming Java Object Oriented Programming
Java Object Oriented Programming
University of Potsdam
 
Introduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingIntroduction to Object Oriented Programming
Introduction to Object Oriented Programming
Md. Tanvir Hossain
 
Object Oriented Programing JAVA presentaion
Object Oriented Programing JAVA presentaionObject Oriented Programing JAVA presentaion
Object Oriented Programing JAVA presentaion
Pritom Chaki
 
Concepts of oops
Concepts of oopsConcepts of oops
Concepts of oops
Sourabrata Mukherjee
 
General oops concepts
General oops conceptsGeneral oops concepts
General oops concepts
nidhiyagnik123
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
Army Public School and College -Faisal
 
Std 12 computer chapter 6 object oriented concepts (part 1)
Std 12 computer chapter 6 object oriented concepts (part 1)Std 12 computer chapter 6 object oriented concepts (part 1)
Std 12 computer chapter 6 object oriented concepts (part 1)
Nuzhat Memon
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
Sandeep Kumar Singh
 
Oops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaOops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in Java
Madishetty Prathibha
 

What's hot (20)

SEMINAR
SEMINARSEMINAR
SEMINAR
 
OOP in Java
OOP in JavaOOP in Java
OOP in Java
 
Oops
OopsOops
Oops
 
concept of oops
concept of oopsconcept of oops
concept of oops
 
General OOP Concepts
General OOP ConceptsGeneral OOP Concepts
General OOP Concepts
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
 
Advanced OOP - Laws, Principles, Idioms
Advanced OOP - Laws, Principles, IdiomsAdvanced OOP - Laws, Principles, Idioms
Advanced OOP - Laws, Principles, Idioms
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
1 unit (oops)
1 unit (oops)1 unit (oops)
1 unit (oops)
 
Oops concept in c++ unit 3 -topic 4
Oops concept in c++ unit 3 -topic 4Oops concept in c++ unit 3 -topic 4
Oops concept in c++ unit 3 -topic 4
 
Oop Presentation
Oop PresentationOop Presentation
Oop Presentation
 
Java Object Oriented Programming
Java Object Oriented Programming Java Object Oriented Programming
Java Object Oriented Programming
 
Introduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingIntroduction to Object Oriented Programming
Introduction to Object Oriented Programming
 
Object Oriented Programing JAVA presentaion
Object Oriented Programing JAVA presentaionObject Oriented Programing JAVA presentaion
Object Oriented Programing JAVA presentaion
 
Concepts of oops
Concepts of oopsConcepts of oops
Concepts of oops
 
General oops concepts
General oops conceptsGeneral oops concepts
General oops concepts
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
Std 12 computer chapter 6 object oriented concepts (part 1)
Std 12 computer chapter 6 object oriented concepts (part 1)Std 12 computer chapter 6 object oriented concepts (part 1)
Std 12 computer chapter 6 object oriented concepts (part 1)
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Oops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaOops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in Java
 

Similar to Unit 2

Inheritance and Polymorphism
Inheritance and PolymorphismInheritance and Polymorphism
Inheritance and Polymorphism
KartikKapgate
 
java part 1 computer science.pptx
java part 1 computer science.pptxjava part 1 computer science.pptx
java part 1 computer science.pptx
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
Inheritance in java
Inheritance in javaInheritance in java
Java session2
Java session2Java session2
Java session2
Rajeev Kumar
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
Arati Gadgil
 
Unit 3 Java
Unit 3 JavaUnit 3 Java
Unit 3 Java
arnold 7490
 
java_vyshali.pdf
java_vyshali.pdfjava_vyshali.pdf
java_vyshali.pdf
Vyshali6
 
Java programming -Object-Oriented Thinking- Inheritance
Java programming -Object-Oriented Thinking- InheritanceJava programming -Object-Oriented Thinking- Inheritance
Java programming -Object-Oriented Thinking- Inheritance
Jyothishmathi Institute of Technology and Science Karimnagar
 
OOP Assign No.03(AP).pdf
OOP Assign No.03(AP).pdfOOP Assign No.03(AP).pdf
OOP Assign No.03(AP).pdf
Anant240318
 
Lecture 12
Lecture 12Lecture 12
Lecture 12
talha ijaz
 
Java htp6e 09
Java htp6e 09Java htp6e 09
Java htp6e 09
Ayesha ch
 
Only oop
Only oopOnly oop
Only oop
anitarooge
 
4th_class.pdf
4th_class.pdf4th_class.pdf
4th_class.pdf
RumiHossain5
 
Chapter 9 java
Chapter 9 javaChapter 9 java
Chapter 9 java
Ahmad sohail Kakar
 
Java presentation
Java presentationJava presentation
Java presentation
Akteruzzaman .
 
Oops
OopsOops
OOPS Characteristics (With Examples in PHP)
OOPS Characteristics (With Examples in PHP)OOPS Characteristics (With Examples in PHP)
OOPS Characteristics (With Examples in PHP)
baabtra.com - No. 1 supplier of quality freshers
 
JAVA PPT -3 BY ADI.pdf
JAVA PPT -3 BY ADI.pdfJAVA PPT -3 BY ADI.pdf
JAVA PPT -3 BY ADI.pdf
Prof. Dr. K. Adisesha
 
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering CollegeObject Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Dhivyaa C.R
 
UNIT III (8).pptx
UNIT III (8).pptxUNIT III (8).pptx
UNIT III (8).pptx
DrDhivyaaCRAssistant
 

Similar to Unit 2 (20)

Inheritance and Polymorphism
Inheritance and PolymorphismInheritance and Polymorphism
Inheritance and Polymorphism
 
java part 1 computer science.pptx
java part 1 computer science.pptxjava part 1 computer science.pptx
java part 1 computer science.pptx
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Java session2
Java session2Java session2
Java session2
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
Unit 3 Java
Unit 3 JavaUnit 3 Java
Unit 3 Java
 
java_vyshali.pdf
java_vyshali.pdfjava_vyshali.pdf
java_vyshali.pdf
 
Java programming -Object-Oriented Thinking- Inheritance
Java programming -Object-Oriented Thinking- InheritanceJava programming -Object-Oriented Thinking- Inheritance
Java programming -Object-Oriented Thinking- Inheritance
 
OOP Assign No.03(AP).pdf
OOP Assign No.03(AP).pdfOOP Assign No.03(AP).pdf
OOP Assign No.03(AP).pdf
 
Lecture 12
Lecture 12Lecture 12
Lecture 12
 
Java htp6e 09
Java htp6e 09Java htp6e 09
Java htp6e 09
 
Only oop
Only oopOnly oop
Only oop
 
4th_class.pdf
4th_class.pdf4th_class.pdf
4th_class.pdf
 
Chapter 9 java
Chapter 9 javaChapter 9 java
Chapter 9 java
 
Java presentation
Java presentationJava presentation
Java presentation
 
Oops
OopsOops
Oops
 
OOPS Characteristics (With Examples in PHP)
OOPS Characteristics (With Examples in PHP)OOPS Characteristics (With Examples in PHP)
OOPS Characteristics (With Examples in PHP)
 
JAVA PPT -3 BY ADI.pdf
JAVA PPT -3 BY ADI.pdfJAVA PPT -3 BY ADI.pdf
JAVA PPT -3 BY ADI.pdf
 
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering CollegeObject Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
 
UNIT III (8).pptx
UNIT III (8).pptxUNIT III (8).pptx
UNIT III (8).pptx
 

More from Amar Jukuntla

Singly linked list
Singly linked listSingly linked list
Singly linked list
Amar Jukuntla
 
Types of files
Types of filesTypes of files
Types of files
Amar Jukuntla
 
Hashing
HashingHashing
Hashing
Amar Jukuntla
 
Planning
Planning Planning
Planning
Amar Jukuntla
 
Problem Solving
Problem Solving Problem Solving
Problem Solving
Amar Jukuntla
 
Intelligent Agents
Intelligent Agents Intelligent Agents
Intelligent Agents
Amar Jukuntla
 
Introduction
IntroductionIntroduction
Introduction
Amar Jukuntla
 
DFS
DFSDFS
Sorting
SortingSorting
Sorting
Amar Jukuntla
 
Sorting
SortingSorting
Sorting
Amar Jukuntla
 
Nature of open source
Nature of open sourceNature of open source
Nature of open source
Amar Jukuntla
 
Linux Directory System: Introduction
Linux Directory System: IntroductionLinux Directory System: Introduction
Linux Directory System: Introduction
Amar Jukuntla
 
Introduction to Data Structures
Introduction to Data StructuresIntroduction to Data Structures
Introduction to Data Structures
Amar Jukuntla
 
Learning
LearningLearning
Learning
Amar Jukuntla
 
First Order Logic resolution
First Order Logic resolutionFirst Order Logic resolution
First Order Logic resolution
Amar Jukuntla
 
First Order Logic
First Order LogicFirst Order Logic
First Order Logic
Amar Jukuntla
 
A*
A*A*
Agents1
Agents1Agents1
Agents1
Amar Jukuntla
 
Need of object oriented programming
Need of object oriented programmingNeed of object oriented programming
Need of object oriented programming
Amar Jukuntla
 

More from Amar Jukuntla (19)

Singly linked list
Singly linked listSingly linked list
Singly linked list
 
Types of files
Types of filesTypes of files
Types of files
 
Hashing
HashingHashing
Hashing
 
Planning
Planning Planning
Planning
 
Problem Solving
Problem Solving Problem Solving
Problem Solving
 
Intelligent Agents
Intelligent Agents Intelligent Agents
Intelligent Agents
 
Introduction
IntroductionIntroduction
Introduction
 
DFS
DFSDFS
DFS
 
Sorting
SortingSorting
Sorting
 
Sorting
SortingSorting
Sorting
 
Nature of open source
Nature of open sourceNature of open source
Nature of open source
 
Linux Directory System: Introduction
Linux Directory System: IntroductionLinux Directory System: Introduction
Linux Directory System: Introduction
 
Introduction to Data Structures
Introduction to Data StructuresIntroduction to Data Structures
Introduction to Data Structures
 
Learning
LearningLearning
Learning
 
First Order Logic resolution
First Order Logic resolutionFirst Order Logic resolution
First Order Logic resolution
 
First Order Logic
First Order LogicFirst Order Logic
First Order Logic
 
A*
A*A*
A*
 
Agents1
Agents1Agents1
Agents1
 
Need of object oriented programming
Need of object oriented programmingNeed of object oriented programming
Need of object oriented programming
 

Recently uploaded

C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
Wahiba Chair Training & Consulting
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
สมใจ จันสุกสี
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 

Recently uploaded (20)

C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 

Unit 2

  • 1. Amar Jukuntla, M.Tech., Assistant Professor, Department Computer Science and Engineering VFSTR Deemed to Be University, Vadlamudi 1
  • 2. § Inheritance-Basics § Member Access Rules § Super § Final § The Object Class § Forms of inheritance § Benefits of Inheritance § Cost of Inheritance § Polymorphism § Method Overriding § Abstract Classes 2
  • 3. § Inheritance is the process of deriving a new class based on already existing class. § The newly derived class is called “subclass” or “childclass”. The existing class is called “superclass” or “baseclass” or “parentclass”. § A subclass is a specialized version of its superclass. It inherits all of the instances variables and methods defined by the “superclass” and it adds its own elements. § Inheritance is the process by which one object acquires the properties of another object. § Inheritance allows code defining one class to be used in other class. § By using “extend” keyword we can inherit a class from an existing class. 3
  • 4. § The general form of a class that inherits a super class is: class subclass_name extends superclass_name{ //instances //methods //variables //…….. } 4
  • 5. § We can specify only one superclass for any subclass that we create. § Java does not support the inheritance of “multiple super classes” into a single subclass. § We can create hierarchy of inheritance, which a subclass becomes a superclass of another subclass.(Hierchial Association). 5
  • 6. 6
  • 7. Base class class A { int i; // public by default private int j; // private to A void setij(int x, int y) { i = x; j = y; } } Subclass class B extends A { int total; void sum() { total = i + j; // ERROR, j is not accessible here } } Accessing class Access { public static void main(String args[]) { B subOb = new B(); subOb.setij(10, 12); subOb.sum(); System.out.println("Total is " + subOb.total); } } 7
  • 9. 9 Declared As Accessible Public Protected Private Class Other Class in the Package Sub Class in the Package Sub Class outside the package Other package
  • 10. §Whenever a subclass needs to refer to its immediate superclass, it can do so by use of the keyword super. §super has two general forms. §The first calls the superclass’ constructor. §The second is used to access a member of the superclass that has been hidden by a member of a subclass. 10
  • 11. A subclass can call a constructor defined by its superclass by use of the following form of super: super(arg-list); Base Class class Box{ double width; double height; double depth; Box(double w, double h, double d) { width=w; height=h; depth=d; } } Sub Class class BoxWeight extends Box{ double weight; BoxWeight(double w,double h,double d,double m) { super(w,h,d); weight=m; } } 11
  • 12. The second form of super acts somewhat like this, except that it always refers to the superclass of the subclass in which it is used. This usage has the following general form: super.member Here, member can be either a method or an instance variable. 12 Base Class class Box{ double width; double height; double depth; double weight; Box(double w, double h, double d) { width=w; height=h; depth=d; } } Sub Class class BoxWeight extends Box{ BoxWeight(double w,double h,double d,double m) { super(w,h,d); super.weight=m; } }
  • 13. class Box{ double width, height,depth; Box() { width = 10;height = 10;depth = 10; } Box(double w, double h, double d) {width=w;height=h;depth=d; } double vol() { return width*height*depth; } } class BoxDemo extends Box { BoxDemo() {//super(10.0,20.0,30.0);} void display() { double w=super.width;double h=super.height;double d=super.depth; System.out.println("Width:"+w+"nDepth:"+d+"nHeight:"+h+"n"); double vol=super.vol(); System.out.println("Volume of the BOX:"+vol); } public static void main(String args[]) { BoxDemo bd=new BoxDemo(); bd.display(); } } 13
  • 14. § The keyword final has three uses. § First, it can be used to create the equivalent of a named constant. § The other two uses of final apply to inheritance. 14
  • 15. class A { final void meth() { System.out.println("This is a final method."); } } class B extends A { void meth() { // ERROR! Can't override. System.out.println("Illegal!"); } } 15
  • 16. §Declaring a class as final implicitly declares all of its methods as final, too. final class A { // ... } // The following class is illegal. class B extends A { // ERROR! Can't subclass A // ... } 16
  • 17. § A subtype is a class that satisfies the principle of substitutability. § A subclass is something constructed using inheritance, whether or not it satisfies the principle of substitutability. § The two concepts are independent. Not all subclasses are subtypes, and (at least in some languages) you can construct subtypes that are not subclasses. § Substitutability is fundamental to many of the powerful software development techniques in OOP. § The idea is that, declared a variable in one type may hold the value of different type. § Substitutability can occur through use of inheritance, whether using extends, or using implements keywords. 17
  • 18. § Substitutability means, the type of the variable does not have to match with the type of the value assigned to that variable. § Substitutability cannot be achieved in conventional languages in C, but can be achieved in Object Oriented languages like Java. § We have already seen the concept of “Assigning a subclass object to superclass variable or reference”. This is called substitutability. Here I am substituting the superclass object with the object of subclass. 18
  • 19. § Specialization § The child class is a special case of the parent class; in other words, the child class is a subtype of the parent class. § Specification § The parent class defines behavior that is implemented in the child class but not in the parent class. § Construction § The child class makes use of the behavior provided by the parent class, but is not a subtype of the parent class. § Extension § The child class adds new functionality to the parent class, but does not change any inherited behavior. § Limitation § The child class restricts the use of some of the behavior inherited from the parent class. § Combination § The child class inherits features from more than one parent class. Although multiple inheritance is not supported directly by Java, it can be simulated in part by classes that use both inheritance and implementation of an interface, or implement two or more interfaces 19
  • 20. § Software reusability § Code sharing § Consistency of interface § Software components § Rapid prototyping § Information hiding 20
  • 21. § Execution speed § Program size § Message-passing overhead § Program complexity 21
  • 22. §Polymorphism § Ability to change form is known as Polymorphism. § Polymorphism means “many forms”. § Method overloading, method overriding, interfaces are the example of Polymorphism. § Example: 22
  • 23. 23
  • 24. § A class that is declared as abstract is known as abstract class. It needs to be extended and its method implemented. It cannot be instantiated. § Example: abstract class A{} § A method that is declared as abstract and does not have implementation is known as abstract method. § Example:abstract void printStatus();//no body and abstract 24
  • 25. abstract class Bike{ abstract void run(); } class Honda4 extends Bike{ void run() { System.out.println("running safely.."); } public static void main(String args[]) { Bike obj = new Honda4(); obj.run(); } } 25
  • 26. § There is one special class, Object, defined by Java. All other classes are subclasses of Object. 26
  • 27. § The methods getClass( ), notify( ), notifyAll( ), and wait( ) are declared as final. You may override the others. § However,notice two methods now: equals( ) and toString( ). § The equals( ) method compares the contents of two objects. It returns true if the objects are equivalent, and false otherwise. The precise definition of equality can vary, depending on the type of objects being compared. § The toString( ) method returns a string that contains a description of the object on which it is called. 27