Inheritance:
It is the concept
of getting the properties of one object of a class to another object of a
class.
‘ Java supports only multilevel
inheritance.
Inheritance
types:
1.Single level inheritance: It is the concept of
extending the features of one class to another class.
Example:
class X
{
Int I;
Void fun1(){}
class Y extends X
{
Int j;
Void fun2(){}
}
2.Multilevel inheritance: One class extending another
class as in a hierarchical structure is termed as multilevel inheritance.
Example:
class X
{
Int I;
Void fun1(){}
class Y extends X
{
Int j;
Void fun2(){}
}
class Z extends Y
{
}
3. Multiple inheritance: One class extending two another
classes simultaneously is known as multiple inheritance.
C++supports
multiple inheritance.
class X
{
Int I;
Void fun1(){}
class Y extends X
{
Int j;
Void fun2(){}
}
class Z extends X, Y
{
}
Java will not support multiple inheritance.
4. Cyclic inheritance: One class extends the next class
and so on and the last class extends the first class forming a circle.
No comments:
Post a Comment