Java Reference
In-Depth Information
p superob = new p ( );
Subob. i = 8;
Subob. j = 7;
Subob. a = 9;
System.out.println (“contents”);
Subob.showij ( );
Subob.showa ( );
System.out.println (“sum of i, j and a”);
}
}
Output
Contents: I and j: 8 7
a: 9
Sum of i, j and a: i + j +a: 24
Main use of inheritance in java is for overriding and code reusability.
Overriding
When sub classes are identical of a super class this scenario is called method
overriding.
It provides the characteristic called polymorphism in java.
Search WWH ::




Custom Search