Accessing SuperClass Members(This super keyword)
if you method overrides one of its superclass's methods you can invokethe overridden method through the use of the keyword super. You can also
use super to refer to a hidden field (although hiding fileds is discouraged).
Consider this class, Superclass.
public class Superclass
{
public void printMethod(){
System.out.println("printed in subclass");
}
}
// here is subclass ,called Subclass that ovrrides printmethod();
class Subclass extends Superclass{
public void printMethod()
{
super.printMethod();
System.out.println("Printed is Subclass");
}
public static void main(String[]arr)
{
Subclass s =new Subclass();
s.printMethod();
}
}
This is output
printed in subclass
printed in subclass
0 comments:
Post a Comment