SlideShare a Scribd company logo
2
Most read
3
Most read
8
Most read
 Single Inheritance
 Multiple Inheritance
 Multilevel Inheritance
 Hierarchical Inheritance
 Hybrid Inheritance
 When a class extends another class (only one
class) then we call it as single inheritance.
Class A
Class B
public class BaseClass
{
Public void display()
{
System,out.println(“ this is base class”);
}
}
Public classs DerivedClass extends BaseClass
{ public void disp()
{
System.out.println(“this is derived class”);
}
Public static void main(String args[])
{
DerivedClass D= new DerivedClass()
D.display();
D.disp();
}
}
OUTPUT
This is base class
This is derived class
 When one class extending more then one
class is called multiple inheritance.
 It can be achieved by using Interfaces.
Class A Class B
Class C
Interface Car
{
Int speed=60;
Public void distanceTravelled();
}
Interface Bus
{
Int distance=100;
Public void spped();
}
Public class Vehicle implements Car,Bus
{
Int avgdistance, avgspeed;
Public void distanceTravelled()
{
Avgdistance=speed*distance;
System.out.println(“Avg distance=“+avgdistance);
}
Public void speed()
{
avgspeed=avgdistance/speed;
System.out.println(“Avg speed=“+avgspeed);
}
Public class void main(String args[])
{
Vehicle v=new Vehicle();
v.distanceTravelled();
v.speed();
}
}
Avg distance= 250
Avg speed=80

More Related Content

PPTX
Inheritance in Object Oriented Programming
PPTX
Inheritance
PPT
Abstract class
PPTX
Inheritance
PPTX
Introduction to OOP(in java) BY Govind Singh
PPTX
Inheritance
PPTX
OOPS IN C++
PPT
Java inheritance
Inheritance in Object Oriented Programming
Inheritance
Abstract class
Inheritance
Introduction to OOP(in java) BY Govind Singh
Inheritance
OOPS IN C++
Java inheritance

What's hot (20)

PPTX
Inheritance in C++
PDF
Inheritance In Java
PPTX
Abstract class in c++
PPTX
Oops concept in c++ unit 3 -topic 4
PPTX
Operator overloading and type conversion in cpp
PPTX
Stream classes in C++
PPT
Packages and interfaces
PPTX
Inheritance in c++
PPT
JAVA OOP
PPTX
Polymorphism in java
PPT
C++ Inheritance
PPTX
Object oriented programming in python
PPTX
Multi level inheritence
PPTX
Object Oriented Programming with C#
PDF
Constructors and destructors
PPSX
PPTX
Inheritance in oops
PPT
11 constructors in derived classes
PPTX
Java constructors
Inheritance in C++
Inheritance In Java
Abstract class in c++
Oops concept in c++ unit 3 -topic 4
Operator overloading and type conversion in cpp
Stream classes in C++
Packages and interfaces
Inheritance in c++
JAVA OOP
Polymorphism in java
C++ Inheritance
Object oriented programming in python
Multi level inheritence
Object Oriented Programming with C#
Constructors and destructors
Inheritance in oops
11 constructors in derived classes
Java constructors
Ad

Viewers also liked (20)

PPTX
Single inheritance
PPTX
PPT
Admission in india 2015
ODP
Andrealozada
PPT
Inheritance
PPTX
Hierarchical inheritance
PDF
Repeat-Frame Selection Algorithm for Frame Rate Video Transcoding
PPTX
San martín
PPTX
stokelecture
PPTX
inheritance in C++
PPS
Inheritance
PDF
4 Genetics - types of inheritance (by Lizzy)
PPT
Inheritance C#
PPSX
El financiamient odef
PPTX
PDF
Facebook marketing event - Big data & social
PDF
C++ Multiple Inheritance
PPTX
Inborn errors of metabolism
PPTX
Experiencia Eratóstenes
Single inheritance
Admission in india 2015
Andrealozada
Inheritance
Hierarchical inheritance
Repeat-Frame Selection Algorithm for Frame Rate Video Transcoding
San martín
stokelecture
inheritance in C++
Inheritance
4 Genetics - types of inheritance (by Lizzy)
Inheritance C#
El financiamient odef
Facebook marketing event - Big data & social
C++ Multiple Inheritance
Inborn errors of metabolism
Experiencia Eratóstenes
Ad

Similar to inheritance (20)

PPTX
Java(inheritance)
PPTX
Ritik (inheritance.cpp)
PPTX
PPTX
Inheritance in Java - An Introduction & types
PPT
Inheritance
PPTX
Inheritence
PPTX
Inheritance Slides
PPTX
PPTX
Inheritance
PPTX
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
PDF
efrecdcxcfxfr125002231fewdsdsfxcdfe25.pdf
PPTX
Chap-3 Inheritance.pptx
PPTX
Inheritance and Interfaces
PPTX
Inheritance in JAVA PPT
PPTX
Inheritance
PPTX
Java inheritance
PPTX
Inheritance in java
PPTX
OOPS_Unit2.inheritance and interface objected oriented programming
PPTX
iheritence.pptx
DOCX
Inheritance
Java(inheritance)
Ritik (inheritance.cpp)
Inheritance in Java - An Introduction & types
Inheritance
Inheritence
Inheritance Slides
Inheritance
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
efrecdcxcfxfr125002231fewdsdsfxcdfe25.pdf
Chap-3 Inheritance.pptx
Inheritance and Interfaces
Inheritance in JAVA PPT
Inheritance
Java inheritance
Inheritance in java
OOPS_Unit2.inheritance and interface objected oriented programming
iheritence.pptx
Inheritance

inheritance

  • 1.  Single Inheritance  Multiple Inheritance  Multilevel Inheritance  Hierarchical Inheritance  Hybrid Inheritance
  • 2.  When a class extends another class (only one class) then we call it as single inheritance. Class A Class B
  • 3. public class BaseClass { Public void display() { System,out.println(“ this is base class”); } } Public classs DerivedClass extends BaseClass { public void disp() { System.out.println(“this is derived class”); } Public static void main(String args[]) {
  • 4. DerivedClass D= new DerivedClass() D.display(); D.disp(); } } OUTPUT This is base class This is derived class
  • 5.  When one class extending more then one class is called multiple inheritance.  It can be achieved by using Interfaces. Class A Class B Class C
  • 6. Interface Car { Int speed=60; Public void distanceTravelled(); } Interface Bus { Int distance=100; Public void spped(); } Public class Vehicle implements Car,Bus { Int avgdistance, avgspeed; Public void distanceTravelled() { Avgdistance=speed*distance; System.out.println(“Avg distance=“+avgdistance);
  • 7. } Public void speed() { avgspeed=avgdistance/speed; System.out.println(“Avg speed=“+avgspeed); } Public class void main(String args[]) { Vehicle v=new Vehicle(); v.distanceTravelled(); v.speed(); } }