Click here to watch in Youtube :
https://www.youtube.com/watch?v=dHqMAZtnJIg&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
Java Tutorial : Java super keyword (Access super class members) |
public class Superclass { String name = "Peter"; public void printMethod() { System.out.println("Printed in Superclass."); } }
public class SubClass extends Superclass { String name = "John"; // overrides printMethod in Superclass public void printMethod() { super.printMethod(); System.out.println("name : " + name); System.out.println("super.name : " + super.name); System.out.println("Printed in Subclass"); } }
public class SuperTest { public static void main(String[] args) { SubClass subClassObj = new SubClass(); subClassObj.printMethod(); } }
Printed in Superclass. name : John super.name : Peter Printed in SubclassClick the below link to download the code:
https://sites.google.com/site/javaee4321/java/SuperKeywordDemo_Access_Members_App.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/SuperKeywordDemo_Access_Members_App
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/d8bcbd739d9d2ceaeec7ee56b1959925c6ec69d4/BasicJava/SuperKeywordDemo_Access_Members_App/?at=master
See also:
No comments:
Post a Comment