Inheritance
- It is also known as Is-A relationship.
- The main advantage of inheritance is code reuse-ability.
- By using extends keyword we can implement Is-A relationship.
example:-
class P
{
public void m1()
{
System.out.println("Parent");
}
}
class C extends P
{
public void m2( )
{
System.out.println("Child");
}
Class Test
{
public static void main(String [ ] args)
{
C c =new C ( );
c.m1( );
c.m2( );
}
}
Output is: