SlideShare a Scribd company logo
INHERITANCE
Inheritance
• Different kinds of objects often have a certain amount of
properties in common with each other.
• For Example:
1. Mountain Bike
2. Road Bike
3. Tandems
• All share the characteristics of bicycles (speed, pedal,
gear).
• Yet each also defines additional features that make them
different: tandem bicycles have two seats and two sets of
handlebars; road bikes have drop handlebars; some
mountain bikes have an additional chain ring
Inheritance
Inheritance
• Inheritance allows the creation of hierarchal
classifications.
• Using inheritance, you can create a general class that
defines traits/features common to a set of related items.
• This class can then be inherited by other classes that add
other things that are unique to them.
• The class that is inherited is called “super class”
• The class that does the inheriting is called “sub class”
• Therefore, the sub class is a specialized version of super
class
• The sub class inherits all the data members and methods
of the super class.
Example
class A
{
int a,b;
A( )
{
a=0;
b=0;
}
public void showab()
{
System.out.println(“The value of a is”+a);
System.out.println(“The value of b is”+b);
}
}
Example cont..
class B extends A
{
int c;
B( )
{
c=0;
}
public void showc()
{
System.out.println(“The value of c is”+c);
}
}
Example cont..
class InheritDriver
{
public static void main(String args[])
{
A obj1=new A();
obj1.a=10;
obj1.b=20;
obj1.showab();
B obj2=new B();
obj2.c=30;
obj2.showc();
obj2.b=40;
obj2.a=20;
obj2.showab();
}
}
Multi level Hierarchy
Inheritance
Inheritance
Inheritance

More Related Content

PPTX
Selective breeding in cows risks
PPTX
Human genetic diseases
PPTX
Adaptation and selective breeding
PPT
Weather - Winds, air masses, air pressures, fronts
PPTX
Sciennes P4-7 Easter Assembly 31.3.17
PPTX
Easter powerpoint
PPTX
inheritance.pptxfdfgfgfgfgdfgfgdfgdfgerre
PDF
java_vyshali.pdf
Selective breeding in cows risks
Human genetic diseases
Adaptation and selective breeding
Weather - Winds, air masses, air pressures, fronts
Sciennes P4-7 Easter Assembly 31.3.17
Easter powerpoint
inheritance.pptxfdfgfgfgfgdfgfgdfgdfgerre
java_vyshali.pdf

Similar to Inheritance (20)

PPTX
Inheritance
PPTX
Inheritance in java
PDF
IRJET- Inheritance in Java
PPTX
Non Text Magic Studio Magic Design for Presentations L&P (2).pptx
PPTX
Ritik (inheritance.cpp)
PPTX
Inheritance in OOPs with java
PDF
Inheritance_abstractclass_interface.pdf
PPTX
inheritance
PDF
java inheritance that is used in oop cls
PPTX
Ayan Das_25300121057.pptx
PPTX
Inheritance in oop
PDF
Inheritance In Java
PPTX
Inheritance in Java is a mechanism in which one object acquires all the prope...
PPTX
Inheritance in java.pptx_20241025_101324_0000.pptx.pptx
PPTX
INHERITANCES.pptx
PPTX
Ch5Inheritance.pptx Java program Java file
PDF
efrecdcxcfxfr125002231fewdsdsfxcdfe25.pdf
PPTX
Inheritance In Java
PPTX
Inheritance.pptx
PPTX
Inheritance
Inheritance in java
IRJET- Inheritance in Java
Non Text Magic Studio Magic Design for Presentations L&P (2).pptx
Ritik (inheritance.cpp)
Inheritance in OOPs with java
Inheritance_abstractclass_interface.pdf
inheritance
java inheritance that is used in oop cls
Ayan Das_25300121057.pptx
Inheritance in oop
Inheritance In Java
Inheritance in Java is a mechanism in which one object acquires all the prope...
Inheritance in java.pptx_20241025_101324_0000.pptx.pptx
INHERITANCES.pptx
Ch5Inheritance.pptx Java program Java file
efrecdcxcfxfr125002231fewdsdsfxcdfe25.pdf
Inheritance In Java
Inheritance.pptx
Ad

Recently uploaded (20)

PDF
Classroom Observation Tools for Teachers
PDF
Insiders guide to clinical Medicine.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Basic Mud Logging Guide for educational purpose
PPTX
master seminar digital applications in india
PDF
Business Ethics Teaching Materials for college
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PPTX
Pharma ospi slides which help in ospi learning
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Classroom Observation Tools for Teachers
Insiders guide to clinical Medicine.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Basic Mud Logging Guide for educational purpose
master seminar digital applications in india
Business Ethics Teaching Materials for college
Microbial diseases, their pathogenesis and prophylaxis
Anesthesia in Laparoscopic Surgery in India
Abdominal Access Techniques with Prof. Dr. R K Mishra
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Pharma ospi slides which help in ospi learning
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Module 4: Burden of Disease Tutorial Slides S2 2025
Pharmacology of Heart Failure /Pharmacotherapy of CHF
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Ad

Inheritance

  • 2. Inheritance • Different kinds of objects often have a certain amount of properties in common with each other. • For Example: 1. Mountain Bike 2. Road Bike 3. Tandems • All share the characteristics of bicycles (speed, pedal, gear). • Yet each also defines additional features that make them different: tandem bicycles have two seats and two sets of handlebars; road bikes have drop handlebars; some mountain bikes have an additional chain ring
  • 4. Inheritance • Inheritance allows the creation of hierarchal classifications. • Using inheritance, you can create a general class that defines traits/features common to a set of related items. • This class can then be inherited by other classes that add other things that are unique to them. • The class that is inherited is called “super class” • The class that does the inheriting is called “sub class” • Therefore, the sub class is a specialized version of super class • The sub class inherits all the data members and methods of the super class.
  • 5. Example class A { int a,b; A( ) { a=0; b=0; } public void showab() { System.out.println(“The value of a is”+a); System.out.println(“The value of b is”+b); } }
  • 6. Example cont.. class B extends A { int c; B( ) { c=0; } public void showc() { System.out.println(“The value of c is”+c); } }
  • 7. Example cont.. class InheritDriver { public static void main(String args[]) { A obj1=new A(); obj1.a=10; obj1.b=20; obj1.showab(); B obj2=new B(); obj2.c=30; obj2.showc(); obj2.b=40; obj2.a=20; obj2.showab(); } }