Tuesday, 2 February 2016

Java Tutorial : Java Super Keyword (Invoke super-class constructor with parameter)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=xkJX-saNFVU&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java Super Keyword (Invoke super-class constructor with parameter) 

SuperClass.java
public class SuperClass
{

    public SuperClass(String name)
    {
        System.out.println("Inside SuperClass(String name) constructor. ");
        System.out.println("name = "+name);     
    }
    
    public SuperClass(String name,int age)
    {
        System.out.println("Inside SuperClass(String name,int age) constructor. ");
        System.out.println("name = "+name);
        System.out.println("age = "+age);
    }

}
SubClass.java
public class SubClass extends SuperClass
{

    public SubClass(String name)
    {
        super(name);
        System.out.println("Inside SubClass(String name) constructor. ");
    }
    
    public SubClass(String name,int age)
    {
        super(name,age);
        System.out.println("Inside SubClass(String name,int age) constructor. ");
    }

}
SuperTest.java
public class SuperTest
{

    public static void main(String[] args)
    {
        SubClass subClassObj1 = new SubClass("Peter");
        System.out.println("--------------------------");
        SubClass subClassObj2 = new SubClass("John",30);
    }
}
Output
Inside SuperClass(String name) constructor. 
name = Peter
Inside SubClass(String name) constructor. 
--------------------------
Inside SuperClass(String name,int age) constructor. 
name = John
age = 30
Inside SubClass(String name,int age) constructor. 

Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/SuperKeywordDemo_Access_Cons_Param_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/SuperKeywordDemo_Access_Cons_Param_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/d8875c098b832b40f6275d60d0a66e8957df40e5/BasicJava/SuperKeywordDemo_Access_Cons_Param_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