SlideShare a Scribd company logo
6
Most read
16
Most read
18
Most read
INHERITANCE
IN ARNAB BHAUMIK
ECE, 3RD YEAR
UNIVERSITY ROLL NO. :
23900315009
GUIDED BY :
SANKHAMITRA ROY
• WHY PROGRAMMING?
• WHY JAVA?
• CLASSES AND OBJECTS
• INTRODUCTION TO INHERITANCE
TYPES OF INHERITANCE
ADVANTAGES AND DISADVANTAGES
CONTENTS
WHY PROGRAMMING?
• Programming is the term that refers to teaching, instructing or giving commands to the computer.
WHY JAVA?
• Simple
• Object-Oriented
• Platform Independent
• Secure
• Robust
• Multithreaded
CLASSES AND OBJECTS
• A class is a blueprint from which individual objects are created.
colour
name
INTRODUCTION TO INHERITANCE
• Inheritance in java is a mechanism in which one class acquires all the properties and behaviours of
another class.
• Sub Class : The class that inherits properties and behaviours from another class is called Sub class or
Derived Class.
• Super Class : The class whose properties and behaviours are inherited by sub class is called Base
Class or Super class.
• Syntax of Java Inheritance
class Subclass-name extends Superclass-name
{
//methods and fields
}
INTRODUCTION TO INHERITANCE
• Why and when to use inheritance?
TYPES OF INHERITANCE
• On the basis of class, there can be mainly three types of inheritance in java:
1. Single
2. Multilevel
3. Hierarchical
SINGLE INHERITANCE
Class A
Class B
SINGLE INHERITANCE
PROGRAM
class Animal {
void eat() {
System.out.println("eating...");
}
}
class Dog extends Animal {
void bark() {
System.out.println("barking...");
}
}
class TestInheritance {
public static void main(String args[ ]) {
Dog d=new Dog();
d.bark();
d.eat();
}
}
OUTPUT
barking...
eating...
MULTILEVEL INHERITANCE
Class A
Class B
Class C
MULTILEVEL INHERITANCE
PROGRAM
class Animal {
void eat() {
System.out.println("eating...");
}
}
class Dog extends Animal {
void bark() {
System.out.println("barking...");
}
}
class BabyDog extends Dog {
void weep() {
System.out.println("weeping...");
}
}
class TestInheritance2 {
public static void main(String args[ ]) {
BabyDog d=new BabyDog();
d.weep();
d.bark();
d.eat();
}
}
OUTPUT
weeping...
barking...
eating...
HIERARCHICAL INHERITANCE
Class A
Class B Class C
HIERARCHICAL INHERITANCE
PROGRAM
class Animal {
void eat() {
System.out.println("eating...");
}
}
class Dog extends Animal {
void bark() {
System.out.println("barking...");
}
}
class Cat extends Animal {
void meow() {
System.out.println("meowing...");
}
}
class TestInheritance3 {
public static void main(String args[ ]) {
Cat c=new Cat();
Dog d=new Dog();
c.meow();
c.eat();
d.bark();
d.eat();
}
}
OUTPUT
meowing...
eating...
barking…
eating…
MULTIPLE AND HYBRID INHERITANCE
Class A Class B
Class C
Class B Class C
Class D
Class A
ADVANTAGES AND DISADVANTAGES
 ADVANTAGES
• Inheritance promotes reusability. When a class inherits or derives another class, it can access all the functionality of
inherited class.
• Reusability enhanced reliability. The base class code will be already tested and debugged.
• As the existing code is reused, it leads to less development and maintenance costs.
 DISADVANTAGES
• Inherited functions work slower than normal function as there is indirection.
• Improper use of inheritance may lead to wrong solutions.
• Often, data members in the base class are left unused which may lead to memory wastage.
• Inheritance increases the coupling between base class and derived class. A change in base class will affect all the
child classes.
References:
• “The Complete Reference Java” by Herbert Schildt.
• “Java Programming Black Book” by Kogent Learning solution.
Inheritance In Java

More Related Content

What's hot (20)

PPT
Inheritance in java
Lovely Professional University
 
PPTX
Inheritance
Sapna Sharma
 
PPS
String and string buffer
kamal kotecha
 
PPTX
Inheritance in JAVA PPT
Pooja Jaiswal
 
PPTX
Method overloading
Lovely Professional University
 
PPT
Polymorphism in java, method overloading and method overriding
JavaTportal
 
PPT
Inheritance C#
Raghuveer Guthikonda
 
PPTX
Access modifiers in java
Madishetty Prathibha
 
PPTX
C# Inheritance
Prem Kumar Badri
 
PPTX
Inheritance In Java
Darpan Chelani
 
PPT
9. Input Output in java
Nilesh Dalvi
 
PDF
Java threads
Prabhakaran V M
 
PPTX
Inheritance in c++
Paumil Patel
 
PPT
Method overriding
Azaz Maverick
 
PDF
Access specifiers (Public Private Protected) C++
vivekkumar2938
 
PPT
Abstract class in java
Lovely Professional University
 
PPTX
Java package
CS_GDRCST
 
PPTX
Polymorphism
Arif Ansari
 
PDF
itft-Inheritance in java
Atul Sehdev
 
PPTX
inheritance c++
Muraleedhar Sundararajan
 
Inheritance in java
Lovely Professional University
 
Inheritance
Sapna Sharma
 
String and string buffer
kamal kotecha
 
Inheritance in JAVA PPT
Pooja Jaiswal
 
Method overloading
Lovely Professional University
 
Polymorphism in java, method overloading and method overriding
JavaTportal
 
Inheritance C#
Raghuveer Guthikonda
 
Access modifiers in java
Madishetty Prathibha
 
C# Inheritance
Prem Kumar Badri
 
Inheritance In Java
Darpan Chelani
 
9. Input Output in java
Nilesh Dalvi
 
Java threads
Prabhakaran V M
 
Inheritance in c++
Paumil Patel
 
Method overriding
Azaz Maverick
 
Access specifiers (Public Private Protected) C++
vivekkumar2938
 
Abstract class in java
Lovely Professional University
 
Java package
CS_GDRCST
 
Polymorphism
Arif Ansari
 
itft-Inheritance in java
Atul Sehdev
 
inheritance c++
Muraleedhar Sundararajan
 

Similar to Inheritance In Java (20)

PPTX
inheritance
Jay Prajapati
 
PDF
Inheritance used in java
TharuniDiddekunta
 
PPTX
INHERITANCE IN JAVA.pptx
NITHISG1
 
PPTX
INHERITANCE.pptx
HARIPRIYA M P
 
PPTX
Inheritance in Java is a mechanism in which one object acquires all the prope...
Kavitha S
 
PDF
java_vyshali.pdf
Vyshali6
 
PPTX
Inheritance in java
Ariful Islam
 
PDF
Inheritance in Java.pdf
kumari36
 
PPTX
Ayan Das_25300121057.pptx
Ayan974999
 
PPTX
Chapter5.pptxfghwryhYETHYETH67IOIKUTJJUILOUI
berihun18
 
PDF
IRJET- Inheritance in Java
IRJET Journal
 
PDF
Presentation Slide about Inharitance in Java Object Oriented Programming
Abdullah Al Noman
 
PPTX
Inheritance in oop
MuskanNazeer
 
PPTX
Inheritance in OOPs with java
AAKANKSHA JAIN
 
PPTX
Ch5Inheritance.pptx Java program Java file
Pravy3
 
PPTX
inheritance.pptxfdfgfgfgfgdfgfgdfgdfgerre
PrincipalSSITGnagar
 
PPTX
INHERITANCES.pptx
VISHNU PRIYA NR
 
PPTX
Inheritance & interface ppt Inheritance
narikamalliy
 
PPTX
Lecture 3
talha ijaz
 
PPTX
Inheritance in java.pptx_20241025_101324_0000.pptx.pptx
saurabhthege
 
inheritance
Jay Prajapati
 
Inheritance used in java
TharuniDiddekunta
 
INHERITANCE IN JAVA.pptx
NITHISG1
 
INHERITANCE.pptx
HARIPRIYA M P
 
Inheritance in Java is a mechanism in which one object acquires all the prope...
Kavitha S
 
java_vyshali.pdf
Vyshali6
 
Inheritance in java
Ariful Islam
 
Inheritance in Java.pdf
kumari36
 
Ayan Das_25300121057.pptx
Ayan974999
 
Chapter5.pptxfghwryhYETHYETH67IOIKUTJJUILOUI
berihun18
 
IRJET- Inheritance in Java
IRJET Journal
 
Presentation Slide about Inharitance in Java Object Oriented Programming
Abdullah Al Noman
 
Inheritance in oop
MuskanNazeer
 
Inheritance in OOPs with java
AAKANKSHA JAIN
 
Ch5Inheritance.pptx Java program Java file
Pravy3
 
inheritance.pptxfdfgfgfgfgdfgfgdfgdfgerre
PrincipalSSITGnagar
 
INHERITANCES.pptx
VISHNU PRIYA NR
 
Inheritance & interface ppt Inheritance
narikamalliy
 
Lecture 3
talha ijaz
 
Inheritance in java.pptx_20241025_101324_0000.pptx.pptx
saurabhthege
 
Ad

Recently uploaded (20)

PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Ad

Inheritance In Java

  • 1. INHERITANCE IN ARNAB BHAUMIK ECE, 3RD YEAR UNIVERSITY ROLL NO. : 23900315009 GUIDED BY : SANKHAMITRA ROY
  • 2. • WHY PROGRAMMING? • WHY JAVA? • CLASSES AND OBJECTS • INTRODUCTION TO INHERITANCE TYPES OF INHERITANCE ADVANTAGES AND DISADVANTAGES CONTENTS
  • 3. WHY PROGRAMMING? • Programming is the term that refers to teaching, instructing or giving commands to the computer.
  • 4. WHY JAVA? • Simple • Object-Oriented • Platform Independent • Secure • Robust • Multithreaded
  • 5. CLASSES AND OBJECTS • A class is a blueprint from which individual objects are created. colour name
  • 6. INTRODUCTION TO INHERITANCE • Inheritance in java is a mechanism in which one class acquires all the properties and behaviours of another class. • Sub Class : The class that inherits properties and behaviours from another class is called Sub class or Derived Class. • Super Class : The class whose properties and behaviours are inherited by sub class is called Base Class or Super class. • Syntax of Java Inheritance class Subclass-name extends Superclass-name { //methods and fields }
  • 7. INTRODUCTION TO INHERITANCE • Why and when to use inheritance?
  • 8. TYPES OF INHERITANCE • On the basis of class, there can be mainly three types of inheritance in java: 1. Single 2. Multilevel 3. Hierarchical
  • 10. SINGLE INHERITANCE PROGRAM class Animal { void eat() { System.out.println("eating..."); } } class Dog extends Animal { void bark() { System.out.println("barking..."); } } class TestInheritance { public static void main(String args[ ]) { Dog d=new Dog(); d.bark(); d.eat(); } } OUTPUT barking... eating...
  • 12. MULTILEVEL INHERITANCE PROGRAM class Animal { void eat() { System.out.println("eating..."); } } class Dog extends Animal { void bark() { System.out.println("barking..."); } } class BabyDog extends Dog { void weep() { System.out.println("weeping..."); } } class TestInheritance2 { public static void main(String args[ ]) { BabyDog d=new BabyDog(); d.weep(); d.bark(); d.eat(); } } OUTPUT weeping... barking... eating...
  • 14. HIERARCHICAL INHERITANCE PROGRAM class Animal { void eat() { System.out.println("eating..."); } } class Dog extends Animal { void bark() { System.out.println("barking..."); } } class Cat extends Animal { void meow() { System.out.println("meowing..."); } } class TestInheritance3 { public static void main(String args[ ]) { Cat c=new Cat(); Dog d=new Dog(); c.meow(); c.eat(); d.bark(); d.eat(); } } OUTPUT meowing... eating... barking… eating…
  • 15. MULTIPLE AND HYBRID INHERITANCE Class A Class B Class C Class B Class C Class D Class A
  • 16. ADVANTAGES AND DISADVANTAGES  ADVANTAGES • Inheritance promotes reusability. When a class inherits or derives another class, it can access all the functionality of inherited class. • Reusability enhanced reliability. The base class code will be already tested and debugged. • As the existing code is reused, it leads to less development and maintenance costs.  DISADVANTAGES • Inherited functions work slower than normal function as there is indirection. • Improper use of inheritance may lead to wrong solutions. • Often, data members in the base class are left unused which may lead to memory wastage. • Inheritance increases the coupling between base class and derived class. A change in base class will affect all the child classes.
  • 17. References: • “The Complete Reference Java” by Herbert Schildt. • “Java Programming Black Book” by Kogent Learning solution.