Accessing SuperClass Members(This super keyword) - LearnHowToCode SarkariResult.com Interview Questions and Answers LearnHowToCodeOnline
Accessing SuperClass Members(This super keyword)

Accessing SuperClass Members(This super keyword)

Accessing SuperClass Members(This super keyword)

if you method overrides one of its superclass's methods you can invoke
the 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























About EasyToCode

I'm Ethan Mariano a software engineer by profession and reader/writter by passion.I have good understanding and knowledge of AngularJS, Database, javascript, web development, digital marketing and exploring other technologies related to Software development.

0 comments:

Featured post

Political Full Forms List

Acronym Full Form MLA Member of Legislative Assembly RSS Really Simple Syndication, Rashtriya Swayamsevak Sangh UNESCO United Nations E...

Powered by Blogger.