Friday, 29 January 2016

Java Tutorial : Java super keyword (Access super class members)


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) 
Superclass.java
public class Superclass
{
    String name = "Peter";
    public void printMethod()
    {
        System.out.println("Printed in Superclass.");
    }
}
SubClass.java
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");
    }

}
SuperTest.java
public class SuperTest
{

    public static void main(String[] args)
    {
        SubClass subClassObj = new SubClass();
        subClassObj.printMethod();
    }
}
Output
Printed in Superclass.
name : John
super.name : Peter
Printed in Subclass
Click 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:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge