SlideShare a Scribd company logo
Inheritance in Java
Prof. Neeraj Bhargava
Kapil Chauhan
Department of Computer Science
School of Engineering & Systems Sciences
MDS University, Ajmer
Introduction
 Inheritance in Java is a mechanism in which one
object acquires all the properties and behaviors of a
parent object. It is an important part of OOPs(Object
Oriented programming system).
 The idea behind inheritance in Java is that you can
create new classes that are built upon existing classes.
 When you inherit from an existing class, you can reuse
methods and fields of the parent class.
Cont..
 Moreover, you can add new methods and fields in your
current class also.
 Inheritance represents the IS-A relationship which is
also known as a parent-child relationship.
Terms used in Inheritance
 Class: A class is a group of objects which have
common properties. It is a template or blueprint from
which objects are created.
 Sub Class/Child Class: Subclass is a class which
inherits the other class. It is also called a derived class,
extended class, or child class.
Cont..
 Super Class/Parent Class: Superclass is the class
from where a subclass inherits the features. It is also
called a base class or a parent class.
 Reusability: As the name specifies, reusability is a
mechanism which facilitates you to reuse the fields
and methods of the existing class when you create a
new class. You can use the same fields and methods
already defined in the previous class.
The syntax of Java Inheritance
 class Subclass-name extends Superclass-name
 {
 //methods and fields
 }
 The extends keyword indicates that you are making a
new class that derives from an existing class. The
meaning of "extends" is to increase the functionality.
Example1
 class Employee{
 float salary=40000;
 }
 class Programmer extends Employee{
 int bonus=10000;
 public static void main(String args[]){
 Programmer p=new Programmer();
 System.out.println("Programmer salary is:"+p.salary);
 System.out.println("Bonus of Programmer is:"+p.bonus);
 }
 }
Example2
 class Calculation {
 int z;

 public void addition(int x, int y) {
 z = x + y;
 System.out.println("The sum of the given numbers:"+z);
 }

 public void Subtraction(int x, int y) {
 z = x - y;
 System.out.println("The difference between the given
numbers:"+z);
 }
 }
Cont..
 public class My_Calculation extends Calculation {
 public void multiplication(int x, int y) {
 z = x * y;
 System.out.println("The product of the given numbers:"+z);
 }

 public static void main(String args[]) {
 int a = 20, b = 10;
 My_Calculation demo = new My_Calculation();
 demo.addition(a, b);
 demo.Subtraction(a, b);
 demo.multiplication(a, b);
 }
 }
Output
 The sum of the given numbers:30
 The difference between the given numbers:10
 The product of the given numbers:200

More Related Content

What's hot (20)

PPTX
Advanced Python : Static and Class Methods
Bhanwar Singh Meena
 
PDF
E3
lksoo
 
PPT
11 Using classes and objects
maznabili
 
PPTX
encapsulation, inheritance, overriding, overloading
Shivam Singhal
 
PDF
Java keywords
Ravi_Kant_Sahu
 
DOCX
Keyword of java
Jani Harsh
 
PPTX
Class properties
Siva Priya
 
PPT
Python3
Ruchika Sinha
 
PPTX
Chapter 7 java
Ahmad sohail Kakar
 
PPT
Chapter 13 - Inheritance and Polymorphism
Eduardo Bergavera
 
PPT
Class and object in C++
rprajat007
 
PDF
Object Oriented Programming using JAVA Notes
Uzair Salman
 
PDF
Methods in Java
Kasun Ranga Wijeweera
 
PDF
Principles of Object Oriented Programming
Kasun Ranga Wijeweera
 
PDF
Lecture1
Ritu Chaturvedi
 
PPTX
Chapter 8.2
sotlsoc
 
PDF
Java Programming Paradigms Chapter 1
Sakthi Durai
 
DOCX
JAVA Notes - All major concepts covered with examples
Sunil Kumar Gunasekaran
 
PPTX
Object Oriented Programming Using C++
Muhammad Waqas
 
PDF
Keywords and classes
Ravi_Kant_Sahu
 
Advanced Python : Static and Class Methods
Bhanwar Singh Meena
 
E3
lksoo
 
11 Using classes and objects
maznabili
 
encapsulation, inheritance, overriding, overloading
Shivam Singhal
 
Java keywords
Ravi_Kant_Sahu
 
Keyword of java
Jani Harsh
 
Class properties
Siva Priya
 
Python3
Ruchika Sinha
 
Chapter 7 java
Ahmad sohail Kakar
 
Chapter 13 - Inheritance and Polymorphism
Eduardo Bergavera
 
Class and object in C++
rprajat007
 
Object Oriented Programming using JAVA Notes
Uzair Salman
 
Methods in Java
Kasun Ranga Wijeweera
 
Principles of Object Oriented Programming
Kasun Ranga Wijeweera
 
Lecture1
Ritu Chaturvedi
 
Chapter 8.2
sotlsoc
 
Java Programming Paradigms Chapter 1
Sakthi Durai
 
JAVA Notes - All major concepts covered with examples
Sunil Kumar Gunasekaran
 
Object Oriented Programming Using C++
Muhammad Waqas
 
Keywords and classes
Ravi_Kant_Sahu
 

Similar to Inheritance in java (20)

PPTX
Inheritance in oop
MuskanNazeer
 
PPTX
Inheritance in Java is a mechanism in which one object acquires all the prope...
Kavitha S
 
PPTX
Inheritance in java.pptx_20241025_101324_0000.pptx.pptx
saurabhthege
 
PPTX
Inheritance in OOPs with java
AAKANKSHA JAIN
 
PPT
A457405934_21789_26_2018_Inheritance.ppt
RithwikRanjan
 
PDF
Inheritance in Java.pdf
kumari36
 
PPTX
Chap-3 Inheritance.pptx
chetanpatilcp783
 
PPTX
Java Inheritance
VINOTH R
 
PPTX
UNIT 5.pptx
CurativeServiceDivis
 
PPTX
Inheritance Slides
Ahsan Raja
 
PPTX
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
RudranilDas11
 
PPT
web program-Inheritance,pack&except in Java.ppt
mcjaya2024
 
PPTX
Inheritance & interface ppt Inheritance
narikamalliy
 
PPT
Module 4 Effect of Reuse on using Inheritance.ppt
ramlingams
 
PDF
Inheritance_abstractclass_interface.pdf
kshitijsaini9
 
PPTX
Inheritance in java
HarshitaAshwani
 
PPTX
Java(inheritance)
Pooja Bhojwani
 
PPTX
Inheritance and Interfaces
NAGASURESH MANOHARAN
 
PPTX
Basics to java programming and concepts of java
1747503gunavardhanre
 
PPTX
Inheritance
ssusera6878f
 
Inheritance in oop
MuskanNazeer
 
Inheritance in Java is a mechanism in which one object acquires all the prope...
Kavitha S
 
Inheritance in java.pptx_20241025_101324_0000.pptx.pptx
saurabhthege
 
Inheritance in OOPs with java
AAKANKSHA JAIN
 
A457405934_21789_26_2018_Inheritance.ppt
RithwikRanjan
 
Inheritance in Java.pdf
kumari36
 
Chap-3 Inheritance.pptx
chetanpatilcp783
 
Java Inheritance
VINOTH R
 
Inheritance Slides
Ahsan Raja
 
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
RudranilDas11
 
web program-Inheritance,pack&except in Java.ppt
mcjaya2024
 
Inheritance & interface ppt Inheritance
narikamalliy
 
Module 4 Effect of Reuse on using Inheritance.ppt
ramlingams
 
Inheritance_abstractclass_interface.pdf
kshitijsaini9
 
Inheritance in java
HarshitaAshwani
 
Java(inheritance)
Pooja Bhojwani
 
Inheritance and Interfaces
NAGASURESH MANOHARAN
 
Basics to java programming and concepts of java
1747503gunavardhanre
 
Inheritance
ssusera6878f
 
Ad

More from chauhankapil (20)

PPTX
Gray level transformation
chauhankapil
 
PPTX
Elements of visual perception
chauhankapil
 
PPTX
JSP Client Request
chauhankapil
 
PPTX
Jsp server response
chauhankapil
 
PPTX
Markov decision process
chauhankapil
 
PPTX
RNN basics in deep learning
chauhankapil
 
PPTX
Introduction to generative adversarial networks (GANs)
chauhankapil
 
PPTX
Bayesian probabilistic interference
chauhankapil
 
PPTX
Jsp
chauhankapil
 
PPTX
Exception handling in java
chauhankapil
 
PPTX
Knowledge acquistion
chauhankapil
 
PPTX
Knowledge based system
chauhankapil
 
PPTX
Introduction of predicate logics
chauhankapil
 
PPTX
Types of inheritance in java
chauhankapil
 
PPTX
Representation of syntax, semantics and Predicate logics
chauhankapil
 
PPTX
Propositional logic
chauhankapil
 
PPTX
Constructors in java
chauhankapil
 
PPTX
Methods in java
chauhankapil
 
PPT
Circular linked list
chauhankapil
 
PPT
Doubly linked list
chauhankapil
 
Gray level transformation
chauhankapil
 
Elements of visual perception
chauhankapil
 
JSP Client Request
chauhankapil
 
Jsp server response
chauhankapil
 
Markov decision process
chauhankapil
 
RNN basics in deep learning
chauhankapil
 
Introduction to generative adversarial networks (GANs)
chauhankapil
 
Bayesian probabilistic interference
chauhankapil
 
Exception handling in java
chauhankapil
 
Knowledge acquistion
chauhankapil
 
Knowledge based system
chauhankapil
 
Introduction of predicate logics
chauhankapil
 
Types of inheritance in java
chauhankapil
 
Representation of syntax, semantics and Predicate logics
chauhankapil
 
Propositional logic
chauhankapil
 
Constructors in java
chauhankapil
 
Methods in java
chauhankapil
 
Circular linked list
chauhankapil
 
Doubly linked list
chauhankapil
 
Ad

Recently uploaded (20)

PPTX
What is Shot Peening | Shot Peening is a Surface Treatment Process
Vibra Finish
 
PDF
Digital water marking system project report
Kamal Acharya
 
PDF
mbse_An_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
PPTX
Numerical-Solutions-of-Ordinary-Differential-Equations.pptx
SAMUKTHAARM
 
PDF
REINFORCEMENT LEARNING IN DECISION MAKING SEMINAR REPORT
anushaashraf20
 
PPTX
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
PDF
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
PPTX
Final Major project a b c d e f g h i j k l m
bharathpsnab
 
PPTX
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
PPT
Footbinding.pptmnmkjkjkknmnnjkkkkkkkkkkkkkk
mamadoundiaye42742
 
PDF
20ES1152 Programming for Problem Solving Lab Manual VRSEC.pdf
Ashutosh Satapathy
 
PPTX
OCS353 DATA SCIENCE FUNDAMENTALS- Unit 1 Introduction to Data Science
A R SIVANESH M.E., (Ph.D)
 
PPT
New_school_Engineering_presentation_011707.ppt
VinayKumar304579
 
PDF
MODULE-5 notes [BCG402-CG&V] PART-B.pdf
Alvas Institute of Engineering and technology, Moodabidri
 
PPTX
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
PDF
WD2(I)-RFQ-GW-1415_ Shifting and Filling of Sand in the Pond at the WD5 Area_...
ShahadathHossain23
 
PPTX
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
PPTX
Biosensors, BioDevices, Biomediccal.pptx
AsimovRiyaz
 
PPT
Testing and final inspection of a solar PV system
MuhammadSanni2
 
PDF
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
What is Shot Peening | Shot Peening is a Surface Treatment Process
Vibra Finish
 
Digital water marking system project report
Kamal Acharya
 
mbse_An_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
Numerical-Solutions-of-Ordinary-Differential-Equations.pptx
SAMUKTHAARM
 
REINFORCEMENT LEARNING IN DECISION MAKING SEMINAR REPORT
anushaashraf20
 
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
Final Major project a b c d e f g h i j k l m
bharathpsnab
 
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
Footbinding.pptmnmkjkjkknmnnjkkkkkkkkkkkkkk
mamadoundiaye42742
 
20ES1152 Programming for Problem Solving Lab Manual VRSEC.pdf
Ashutosh Satapathy
 
OCS353 DATA SCIENCE FUNDAMENTALS- Unit 1 Introduction to Data Science
A R SIVANESH M.E., (Ph.D)
 
New_school_Engineering_presentation_011707.ppt
VinayKumar304579
 
MODULE-5 notes [BCG402-CG&V] PART-B.pdf
Alvas Institute of Engineering and technology, Moodabidri
 
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
WD2(I)-RFQ-GW-1415_ Shifting and Filling of Sand in the Pond at the WD5 Area_...
ShahadathHossain23
 
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
Biosensors, BioDevices, Biomediccal.pptx
AsimovRiyaz
 
Testing and final inspection of a solar PV system
MuhammadSanni2
 
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 

Inheritance in java

  • 1. Inheritance in Java Prof. Neeraj Bhargava Kapil Chauhan Department of Computer Science School of Engineering & Systems Sciences MDS University, Ajmer
  • 2. Introduction  Inheritance in Java is a mechanism in which one object acquires all the properties and behaviors of a parent object. It is an important part of OOPs(Object Oriented programming system).  The idea behind inheritance in Java is that you can create new classes that are built upon existing classes.  When you inherit from an existing class, you can reuse methods and fields of the parent class.
  • 3. Cont..  Moreover, you can add new methods and fields in your current class also.  Inheritance represents the IS-A relationship which is also known as a parent-child relationship.
  • 4. Terms used in Inheritance  Class: A class is a group of objects which have common properties. It is a template or blueprint from which objects are created.  Sub Class/Child Class: Subclass is a class which inherits the other class. It is also called a derived class, extended class, or child class.
  • 5. Cont..  Super Class/Parent Class: Superclass is the class from where a subclass inherits the features. It is also called a base class or a parent class.  Reusability: As the name specifies, reusability is a mechanism which facilitates you to reuse the fields and methods of the existing class when you create a new class. You can use the same fields and methods already defined in the previous class.
  • 6. The syntax of Java Inheritance  class Subclass-name extends Superclass-name  {  //methods and fields  }  The extends keyword indicates that you are making a new class that derives from an existing class. The meaning of "extends" is to increase the functionality.
  • 7. Example1  class Employee{  float salary=40000;  }  class Programmer extends Employee{  int bonus=10000;  public static void main(String args[]){  Programmer p=new Programmer();  System.out.println("Programmer salary is:"+p.salary);  System.out.println("Bonus of Programmer is:"+p.bonus);  }  }
  • 8. Example2  class Calculation {  int z;   public void addition(int x, int y) {  z = x + y;  System.out.println("The sum of the given numbers:"+z);  }   public void Subtraction(int x, int y) {  z = x - y;  System.out.println("The difference between the given numbers:"+z);  }  }
  • 9. Cont..  public class My_Calculation extends Calculation {  public void multiplication(int x, int y) {  z = x * y;  System.out.println("The product of the given numbers:"+z);  }   public static void main(String args[]) {  int a = 20, b = 10;  My_Calculation demo = new My_Calculation();  demo.addition(a, b);  demo.Subtraction(a, b);  demo.multiplication(a, b);  }  }
  • 10. Output  The sum of the given numbers:30  The difference between the given numbers:10  The product of the given numbers:200