Types of Inheritance in Java
There are five types of inheritance . Types are 1)Single 2) Multilevel 3) Multiple
4) Hybrid 5) Hierarchical . But Java supports four types of inheritance . Java does not support " Multiple Inheritance ".
1)Single :
public class A{
................
}
public class B extends A{
.................
}
Supports
2) Multilevel :
public class A{
................
}
public class B extends A{
.................
}
public class C extends B{
.................
}
Supports
3) Multiple :
public class A{
................
}
public class B{
................
}
public class C extends A,B{
................
}
It's generate a compile time error. So Multiple inheritance does not support
in Java.
4) Hybrid :
public class A{
................
}
public class B extends A{
................
}
public class C extends A{
................
}
public class D extends B,C{
................
}
It's generate a compile time error . So the solution is given bellow .
interface A{
................
}
interface B extends A{
................
}
interface C extends A{
................
}
public class D implements B,C{
................
}
Supports
5) Hierarchical :
public class A{
................
}
public class B extends A{
.................
}
public class C extends A{
.................
}
Supports
Find us :
Facebook : @apnaandroid
Google+ : Apna Java
Youtube : Android & Java Tutorial
4) Hybrid 5) Hierarchical . But Java supports four types of inheritance . Java does not support " Multiple Inheritance ".
1)Single :
public class A{
................
}
public class B extends A{
.................
}
Supports
2) Multilevel :
public class A{
................
}
public class B extends A{
.................
}
public class C extends B{
.................
}
Supports
3) Multiple :
public class A{
................
}
public class B{
................
}
public class C extends A,B{
................
}
It's generate a compile time error. So Multiple inheritance does not support
in Java.
4) Hybrid :
public class A{
................
}
public class B extends A{
................
}
public class C extends A{
................
}
public class D extends B,C{
................
}
It's generate a compile time error . So the solution is given bellow .
interface A{
................
}
interface B extends A{
................
}
interface C extends A{
................
}
public class D implements B,C{
................
}
Supports
5) Hierarchical :
public class A{
................
}
public class B extends A{
.................
}
public class C extends A{
.................
}
Supports
Find us :
Facebook : @apnaandroid
Google+ : Apna Java
Youtube : Android & Java Tutorial
Comments
Post a Comment