Search This Blog

Thursday, 14 April 2011

Types of Inheritance

1.Simple inheritance
Simple inhertance means one class extends the the class
Class B extends A
B is the sub class and A is sub class
2.Multiple inheritance
Java implements multiple inheritance through interfaces but not through classes
multiple inheritance example
interface A
interface B
class C implements B,A
so multiple inheritance means one class can have one or more super classes.
3.Hybrid inheritance:
Suppose take an example
class A
class B extends A
class C extends B
means here class C has two super class B inturn B has a super class A
Advantages of inheritance
Main advantage of inheritance is code reusability
means the code in one class can be reused with out writing the code again.

No comments:

Post a Comment