Lecture 9 Inheritance
Lecture 9 Inheritance
Lecture 9 Inheritance
INHERITANCE
Swapnali Kurhade
Sardar Patel Institute of Technology
INHERITANCE
INHERITANCE
Single Inheritance
Multilevel Inheritance
“Multiple Inheritance”
Hierarchical Inheritance
“Hybrid Inheritance”
EXTENDS KEYWORD
class herit{
int a=10; O/P:
} 10
class grandpa{
O/P:
int age=90;
Gradfather age=90
} Father age=60
class pa extends grandpa{
int age1=60;
}
public class JavaApplication26 extends pa{
public static void main(String[] args) {
JavaApplication26 ob1 = new JavaApplication26 ();
System.out.println ("Gradfather
age="+ob1.age+"\nFather age="+ob1.age1);
}
}
HIERARCHICAL INHERITANCE
class student{
Hey you are a student
void display()
Welcome
{System.out.println ("Hey you are a student");} Hey you are a student
} Welcome to Science
class ar ts extends student{
void display1() { display(); System.out.println ("Wel come to ar ts");}
}
class science extends student {
void display2() { display();
System.out.println ("Welcome to Science");}
}
public class JavaApplicati on26 {
public static void main(String[] args) {
ar ts ob1=new ar ts (); ob1 .display1 ();
science ob2=new science(); ob2.display2();
} }
MULTIPLE INHERITANCE