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

PDF
Python - object oriented
PPTX
PPTX
Inheritance in Java
PDF
Python Class | Python Programming | Python Tutorial | Edureka
PDF
itft-Inheritance in java
PPTX
Chapter 07 inheritance
PPT
Python session 7 by Shan
PPTX
Java Inheritance
Python - object oriented
Inheritance in Java
Python Class | Python Programming | Python Tutorial | Edureka
itft-Inheritance in java
Chapter 07 inheritance
Python session 7 by Shan
Java Inheritance

What's hot (20)

PPTX
Advanced Python : Static and Class Methods
PDF
E3
PPT
11 Using classes and objects
PPTX
encapsulation, inheritance, overriding, overloading
PDF
Java keywords
DOCX
Keyword of java
PPTX
Class properties
PPT
Python3
PPTX
Chapter 7 java
PPT
Chapter 13 - Inheritance and Polymorphism
PPT
Class and object in C++
PDF
Object Oriented Programming using JAVA Notes
PDF
Methods in Java
PDF
Principles of Object Oriented Programming
PDF
Lecture1
PPTX
Chapter 8.2
PDF
Java Programming Paradigms Chapter 1
DOCX
JAVA Notes - All major concepts covered with examples
PPTX
Object Oriented Programming Using C++
PDF
Keywords and classes
Advanced Python : Static and Class Methods
E3
11 Using classes and objects
encapsulation, inheritance, overriding, overloading
Java keywords
Keyword of java
Class properties
Python3
Chapter 7 java
Chapter 13 - Inheritance and Polymorphism
Class and object in C++
Object Oriented Programming using JAVA Notes
Methods in Java
Principles of Object Oriented Programming
Lecture1
Chapter 8.2
Java Programming Paradigms Chapter 1
JAVA Notes - All major concepts covered with examples
Object Oriented Programming Using C++
Keywords and classes
Ad

Similar to Inheritance in java (20)

PPTX
Inheritance in oop
PDF
Inheritance in Java.pdf
PPTX
Inheritance in Java is a mechanism in which one object acquires all the prope...
PPT
A457405934_21789_26_2018_Inheritance.ppt
PPTX
Inheritance
PPTX
Chap-3 Inheritance.pptx
PPTX
Inheritance in Java beginner to advance with examples.pptx
PPT
Chapter 5 (OOP Principles).ppt
PPTX
Inheritance in java
PPT
web program-Inheritance,pack&except in Java.ppt
PPTX
INHERITANCE.pptx
PPTX
Inheritance & interface ppt Inheritance
PPTX
Inheritance Interface and Packags in java programming.pptx
PPTX
Unit No 3 Inheritance annd Polymorphism.pptx
PDF
java_inheritance.pdf
PPTX
Inheritance in OOPs with java
PDF
Inheritance used in java
PPTX
Inheritance and Polymorphism in java simple and clear
PPTX
inheritance in Java with sample program.pptx
PPTX
Java Inheritance - sub class constructors - Method overriding
Inheritance in oop
Inheritance in Java.pdf
Inheritance in Java is a mechanism in which one object acquires all the prope...
A457405934_21789_26_2018_Inheritance.ppt
Inheritance
Chap-3 Inheritance.pptx
Inheritance in Java beginner to advance with examples.pptx
Chapter 5 (OOP Principles).ppt
Inheritance in java
web program-Inheritance,pack&except in Java.ppt
INHERITANCE.pptx
Inheritance & interface ppt Inheritance
Inheritance Interface and Packags in java programming.pptx
Unit No 3 Inheritance annd Polymorphism.pptx
java_inheritance.pdf
Inheritance in OOPs with java
Inheritance used in java
Inheritance and Polymorphism in java simple and clear
inheritance in Java with sample program.pptx
Java Inheritance - sub class constructors - Method overriding
Ad

More from chauhankapil (20)

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

Recently uploaded (20)

PDF
Geotechnical Engineering, Soil mechanics- Soil Testing.pdf
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
ETO & MEO Certificate of Competency Questions and Answers
PPTX
TE-AI-Unit VI notes using planning model
PPT
Chapter 6 Design in software Engineeing.ppt
PDF
Queuing formulas to evaluate throughputs and servers
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PDF
Monitoring Global Terrestrial Surface Water Height using Remote Sensing - ARS...
PPTX
The-Looming-Shadow-How-AI-Poses-Dangers-to-Humanity.pptx
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
Practice Questions on recent development part 1.pptx
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPTX
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
PPTX
Internship_Presentation_Final engineering.pptx
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
flutter Launcher Icons, Splash Screens & Fonts
PPTX
24AI201_AI_Unit_4 (1).pptx Artificial intelligence
PPTX
OOP with Java - Java Introduction (Basics)
Geotechnical Engineering, Soil mechanics- Soil Testing.pdf
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
ETO & MEO Certificate of Competency Questions and Answers
TE-AI-Unit VI notes using planning model
Chapter 6 Design in software Engineeing.ppt
Queuing formulas to evaluate throughputs and servers
Model Code of Practice - Construction Work - 21102022 .pdf
Monitoring Global Terrestrial Surface Water Height using Remote Sensing - ARS...
The-Looming-Shadow-How-AI-Poses-Dangers-to-Humanity.pptx
Operating System & Kernel Study Guide-1 - converted.pdf
Practice Questions on recent development part 1.pptx
Strings in CPP - Strings in C++ are sequences of characters used to store and...
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
Internship_Presentation_Final engineering.pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
flutter Launcher Icons, Splash Screens & Fonts
24AI201_AI_Unit_4 (1).pptx Artificial intelligence
OOP with Java - Java Introduction (Basics)

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