SlideShare una empresa de Scribd logo
1 de 14
Descargar para leer sin conexión
Inheritence
Inheritance is a fundamental Object Oriented
concept
A class can be defined as a "subclass" of
another class.
The subclass inherits all data attributes of its superclass
The subclass inherits all methods of its superclass
The subclass inherits all associations of its superclass
The subclass can:
Add new functionality
Use inherited functionality
Override inherited functionality
Person
- name: String
- dob: Date
Employee
- employeeID: int
- salary: int
- startDate: Date
superclass:
subclass:
Terminology
Inheritance is declared using the "extends" keyword
If inheritance is not defined, the class extends a class called Object
Person
- name: String
- dob: Date
Employee
- employeeID: int
- salary: int
- startDate: Date
public class Person
{
private String name;
private Date dob;
[...]
public class Employee extends Person
{
private int employeID;
private int salary;
private Date startDate;
[...]
Employee anEmployee = new Employee();
Inheritance in java
At the very top of the inheritance tree is a class
called Object
All Java classes inherit from Object.
All objects have a common ancestor
This is different from C++
The Object class is defined in the java.lang
package
Examine it in the Java API Specification
The class called Object
Superclass constructors can be called using the
"super" keyword.
It must be the first line of code in the constructor
If a call to super is not made, the system will
automatically attempt to invoke the no-argument
constructor of the superclass.
Super keyword
public class BankAccount
{
private String ownersName;
private int accountNumber;
private float balance;
public BankAccount(int anAccountNumber, String aName)
{
accountNumber = anAccountNumber;
ownersName = aName;
}
}
public class OverdraftAccount extends BankAccount
{
private float overdraftLimit;
public OverdraftAccount(int anAccountNumber, String aName, float aLimit)
{
super(anAccountNumber, aName);
overdraftLimit = aLimit;}}
Example
Method Overriding
• If a derived or sub class has a method found
within its base class or super class, that method
will override the base class’s method
• The keyword super can be used to gain access to
superclass methods overridden by the base class
• A subclass method must have the same return
type as the corresponding superclass method
public class Abc
{
void display()
{
System.out.println(“Hello”);
}
}
public class Xyz extends Abc Output
{
void display() World
{
System.out.println(“World”);
}
public static void main(string str[])
{
Xyz obj = new Xyz();
obj.display();
} }
Example
public class Abc
{
void display()
{
System.out.println(“Hello”);
}
}
public class Xyz extends Abc Output
{
void display() Hello
{ World
super.display(); //this call Abc display()
System.out.println(“World”);
}
public static void main(string str[])
{
Xyz obj = new Xyz();
obj.display();
} }
Continue...
Abstract Class
• An abstract class can have abstract methods, data
fields, and concrete methods
• Abstract class differs from a concrete class in that
• An abstract class cannot be instantiated
• An abstract class can declare abstract methods,
which must be implemented in its subclasses
Abstract Class Number and the
Java Wrapper Classes
Chapter 3: Inheritance and Class Hierarchies 11
Final Method and Classes
Methods can be qualified with the final
modifier
Final methods cannot be overridden.
This can be useful for security purposes.
Classes can be qualified with the final modifier
The class cannot be extended.
Multiple Inheritance
• Multiple inheritance: the ability to extend more
than one class
• Multiple inheritance is a language feature that is
difficult to implement and can lead to ambiguity
• Therefore, Java does not allow a class to extend more
than one class
Inheritance is a fundamental Object Oriented concept

Más contenido relacionado

La actualidad más candente

Introduction to method overloading & method overriding in java hdm
Introduction to method overloading & method overriding  in java  hdmIntroduction to method overloading & method overriding  in java  hdm
Introduction to method overloading & method overriding in java hdmHarshal Misalkar
 
collection framework in java
collection framework in javacollection framework in java
collection framework in javaMANOJ KUMAR
 
Polymorphism In Java
Polymorphism In JavaPolymorphism In Java
Polymorphism In JavaSpotle.ai
 
Collections - Maps
Collections - Maps Collections - Maps
Collections - Maps Hitesh-Java
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in javaHitesh Kumar
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections frameworkRiccardo Cardin
 
Collections In Java
Collections In JavaCollections In Java
Collections In JavaBinoj T E
 
20.2 Java inheritance
20.2 Java inheritance20.2 Java inheritance
20.2 Java inheritanceIntro C# Book
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methodsShubham Dwivedi
 
Java Collections
Java CollectionsJava Collections
Java Collectionsparag
 

La actualidad más candente (20)

Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
inheritance
inheritanceinheritance
inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Introduction to method overloading & method overriding in java hdm
Introduction to method overloading & method overriding  in java  hdmIntroduction to method overloading & method overriding  in java  hdm
Introduction to method overloading & method overriding in java hdm
 
collection framework in java
collection framework in javacollection framework in java
collection framework in java
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
 
Inheritance C#
Inheritance C#Inheritance C#
Inheritance C#
 
Polymorphism In Java
Polymorphism In JavaPolymorphism In Java
Polymorphism In Java
 
Collections - Maps
Collections - Maps Collections - Maps
Collections - Maps
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections framework
 
07 java collection
07 java collection07 java collection
07 java collection
 
Chapter 07 inheritance
Chapter 07 inheritanceChapter 07 inheritance
Chapter 07 inheritance
 
Inheritance in OOPS
Inheritance in OOPSInheritance in OOPS
Inheritance in OOPS
 
Collections In Java
Collections In JavaCollections In Java
Collections In Java
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
20.2 Java inheritance
20.2 Java inheritance20.2 Java inheritance
20.2 Java inheritance
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
Abstract class
Abstract classAbstract class
Abstract class
 
Java Collections
Java CollectionsJava Collections
Java Collections
 

Destacado

Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPTPooja Jaiswal
 
Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in JavaKurapati Vishwak
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in javaTech_MX
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: InheritanceTareq Hasan
 
Learn java objects inheritance-overriding-polymorphism
Learn java objects  inheritance-overriding-polymorphismLearn java objects  inheritance-overriding-polymorphism
Learn java objects inheritance-overriding-polymorphismTOPS Technologies
 
"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
 
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 nowSocial 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 ServerPedrangas Pedrangas
 
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
 
The applicationform
The applicationformThe applicationform
The applicationformjavatwojava
 
ITFT- C,c++,java and world wide web
ITFT- C,c++,java and world wide webITFT- C,c++,java and world wide web
ITFT- C,c++,java and world wide webAtul Sehdev
 
Inheritance question class 12th
Inheritance question class 12thInheritance question class 12th
Inheritance question class 12thAAKASH KUMAR
 
itft-Overview of java language
itft-Overview of java languageitft-Overview of java language
itft-Overview of java languageAtul Sehdev
 
Inheritance and Polymorphism Java
Inheritance and Polymorphism JavaInheritance and Polymorphism Java
Inheritance and Polymorphism JavaM. Raihan
 

Destacado (20)

Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
 
Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in Java
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 
04inherit
04inherit04inherit
04inherit
 
Learn java objects inheritance-overriding-polymorphism
Learn java objects  inheritance-overriding-polymorphismLearn java objects  inheritance-overriding-polymorphism
Learn java objects inheritance-overriding-polymorphism
 
Inheritance
InheritanceInheritance
Inheritance
 
"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"
 
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
 
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
 
Java Inheritance
Java InheritanceJava Inheritance
Java Inheritance
 
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)
 
The applicationform
The applicationformThe applicationform
The applicationform
 
ITFT- C,c++,java and world wide web
ITFT- C,c++,java and world wide webITFT- C,c++,java and world wide web
ITFT- C,c++,java and world wide web
 
Polymorphism (2)
Polymorphism (2)Polymorphism (2)
Polymorphism (2)
 
Inheritance question class 12th
Inheritance question class 12thInheritance question class 12th
Inheritance question class 12th
 
itft-Overview of java language
itft-Overview of java languageitft-Overview of java language
itft-Overview of java language
 
Inheritance and Polymorphism Java
Inheritance and Polymorphism JavaInheritance and Polymorphism Java
Inheritance and Polymorphism Java
 
OOP Inheritance
OOP InheritanceOOP Inheritance
OOP Inheritance
 

Similar a Inheritance is a fundamental Object Oriented concept

Inheritance Slides
Inheritance SlidesInheritance Slides
Inheritance SlidesAhsan Raja
 
9781439035665 ppt ch10
9781439035665 ppt ch109781439035665 ppt ch10
9781439035665 ppt ch10Terry Yoast
 
JAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesJAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesSunil Kumar Gunasekaran
 
Java Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overridingJava Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overridingNithyaN19
 
C h 04 oop_inheritance
C h 04 oop_inheritanceC h 04 oop_inheritance
C h 04 oop_inheritanceshatha00
 
Chapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).pptChapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).ppthenokmetaferia1
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Javabackdoor
 
Unit3 inheritance
Unit3 inheritanceUnit3 inheritance
Unit3 inheritanceKalai Selvi
 
Class notes(week 6) on inheritance and multiple inheritance
Class notes(week 6) on inheritance and multiple inheritanceClass notes(week 6) on inheritance and multiple inheritance
Class notes(week 6) on inheritance and multiple inheritanceKuntal Bhowmick
 

Similar a Inheritance is a fundamental Object Oriented concept (20)

Chap-3 Inheritance.pptx
Chap-3 Inheritance.pptxChap-3 Inheritance.pptx
Chap-3 Inheritance.pptx
 
Inheritance Slides
Inheritance SlidesInheritance Slides
Inheritance Slides
 
Java
JavaJava
Java
 
9781439035665 ppt ch10
9781439035665 ppt ch109781439035665 ppt ch10
9781439035665 ppt ch10
 
Core java oop
Core java oopCore java oop
Core java oop
 
OOPs & Inheritance Notes
OOPs & Inheritance NotesOOPs & Inheritance Notes
OOPs & Inheritance Notes
 
JAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesJAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examples
 
Chap11
Chap11Chap11
Chap11
 
Java Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overridingJava Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overriding
 
C h 04 oop_inheritance
C h 04 oop_inheritanceC h 04 oop_inheritance
C h 04 oop_inheritance
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
 
Unit3 part2-inheritance
Unit3 part2-inheritanceUnit3 part2-inheritance
Unit3 part2-inheritance
 
Chapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).pptChapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).ppt
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Inheritance
InheritanceInheritance
Inheritance
 
Unit3 inheritance
Unit3 inheritanceUnit3 inheritance
Unit3 inheritance
 
Java Basic day-2
Java Basic day-2Java Basic day-2
Java Basic day-2
 
Class notes(week 6) on inheritance and multiple inheritance
Class notes(week 6) on inheritance and multiple inheritanceClass notes(week 6) on inheritance and multiple inheritance
Class notes(week 6) on inheritance and multiple inheritance
 
java tutorial 3
 java tutorial 3 java tutorial 3
java tutorial 3
 
13 inheritance
13   inheritance13   inheritance
13 inheritance
 

Más de Atul Sehdev

itft-Operators in java
itft-Operators in javaitft-Operators in java
itft-Operators in javaAtul Sehdev
 
itft-Java evolution
itft-Java evolutionitft-Java evolution
itft-Java evolutionAtul Sehdev
 
itft-Fundamentals of object–oriented programming in java
itft-Fundamentals of object–oriented programming in javaitft-Fundamentals of object–oriented programming in java
itft-Fundamentals of object–oriented programming in javaAtul Sehdev
 
itft-Decision making and branching in java
itft-Decision making and branching in javaitft-Decision making and branching in java
itft-Decision making and branching in javaAtul Sehdev
 
ITFT-Constants, variables and data types in java
ITFT-Constants, variables and data types in javaITFT-Constants, variables and data types in java
ITFT-Constants, variables and data types in javaAtul Sehdev
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in javaAtul Sehdev
 
ITFT- Applet in java
ITFT- Applet in javaITFT- Applet in java
ITFT- Applet in javaAtul Sehdev
 

Más de Atul Sehdev (7)

itft-Operators in java
itft-Operators in javaitft-Operators in java
itft-Operators in java
 
itft-Java evolution
itft-Java evolutionitft-Java evolution
itft-Java evolution
 
itft-Fundamentals of object–oriented programming in java
itft-Fundamentals of object–oriented programming in javaitft-Fundamentals of object–oriented programming in java
itft-Fundamentals of object–oriented programming in java
 
itft-Decision making and branching in java
itft-Decision making and branching in javaitft-Decision making and branching in java
itft-Decision making and branching in java
 
ITFT-Constants, variables and data types in java
ITFT-Constants, variables and data types in javaITFT-Constants, variables and data types in java
ITFT-Constants, variables and data types in java
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
 
ITFT- Applet in java
ITFT- Applet in javaITFT- Applet in java
ITFT- Applet in java
 

Último

CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxCLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxAnupam32727
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research DiscourseAnita GoswamiGiri
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptxmary850239
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptxDhatriParmar
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...DhatriParmar
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxkarenfajardo43
 
Sulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesSulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesVijayaLaxmi84
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Developmentchesterberbo7
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1GloryAnnCastre1
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17Celine George
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...DhatriParmar
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfPrerana Jadhav
 
ARTERIAL BLOOD GAS ANALYSIS........pptx
ARTERIAL BLOOD  GAS ANALYSIS........pptxARTERIAL BLOOD  GAS ANALYSIS........pptx
ARTERIAL BLOOD GAS ANALYSIS........pptxAneriPatwari
 

Último (20)

CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxCLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research Discourse
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
 
Sulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesSulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their uses
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Development
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdf
 
ARTERIAL BLOOD GAS ANALYSIS........pptx
ARTERIAL BLOOD  GAS ANALYSIS........pptxARTERIAL BLOOD  GAS ANALYSIS........pptx
ARTERIAL BLOOD GAS ANALYSIS........pptx
 

Inheritance is a fundamental Object Oriented concept

  • 2. Inheritance is a fundamental Object Oriented concept A class can be defined as a "subclass" of another class. The subclass inherits all data attributes of its superclass The subclass inherits all methods of its superclass The subclass inherits all associations of its superclass The subclass can: Add new functionality Use inherited functionality Override inherited functionality Person - name: String - dob: Date Employee - employeeID: int - salary: int - startDate: Date superclass: subclass: Terminology
  • 3. Inheritance is declared using the "extends" keyword If inheritance is not defined, the class extends a class called Object Person - name: String - dob: Date Employee - employeeID: int - salary: int - startDate: Date public class Person { private String name; private Date dob; [...] public class Employee extends Person { private int employeID; private int salary; private Date startDate; [...] Employee anEmployee = new Employee(); Inheritance in java
  • 4. At the very top of the inheritance tree is a class called Object All Java classes inherit from Object. All objects have a common ancestor This is different from C++ The Object class is defined in the java.lang package Examine it in the Java API Specification The class called Object
  • 5. Superclass constructors can be called using the "super" keyword. It must be the first line of code in the constructor If a call to super is not made, the system will automatically attempt to invoke the no-argument constructor of the superclass. Super keyword
  • 6. public class BankAccount { private String ownersName; private int accountNumber; private float balance; public BankAccount(int anAccountNumber, String aName) { accountNumber = anAccountNumber; ownersName = aName; } } public class OverdraftAccount extends BankAccount { private float overdraftLimit; public OverdraftAccount(int anAccountNumber, String aName, float aLimit) { super(anAccountNumber, aName); overdraftLimit = aLimit;}} Example
  • 7. Method Overriding • If a derived or sub class has a method found within its base class or super class, that method will override the base class’s method • The keyword super can be used to gain access to superclass methods overridden by the base class • A subclass method must have the same return type as the corresponding superclass method
  • 8. public class Abc { void display() { System.out.println(“Hello”); } } public class Xyz extends Abc Output { void display() World { System.out.println(“World”); } public static void main(string str[]) { Xyz obj = new Xyz(); obj.display(); } } Example
  • 9. public class Abc { void display() { System.out.println(“Hello”); } } public class Xyz extends Abc Output { void display() Hello { World super.display(); //this call Abc display() System.out.println(“World”); } public static void main(string str[]) { Xyz obj = new Xyz(); obj.display(); } } Continue...
  • 10. Abstract Class • An abstract class can have abstract methods, data fields, and concrete methods • Abstract class differs from a concrete class in that • An abstract class cannot be instantiated • An abstract class can declare abstract methods, which must be implemented in its subclasses
  • 11. Abstract Class Number and the Java Wrapper Classes Chapter 3: Inheritance and Class Hierarchies 11
  • 12. Final Method and Classes Methods can be qualified with the final modifier Final methods cannot be overridden. This can be useful for security purposes. Classes can be qualified with the final modifier The class cannot be extended.
  • 13. Multiple Inheritance • Multiple inheritance: the ability to extend more than one class • Multiple inheritance is a language feature that is difficult to implement and can lead to ambiguity • Therefore, Java does not allow a class to extend more than one class