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); } }
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. "); } }
public class SuperTest { public static void main(String[] args) { SubClass subClassObj1 = new SubClass("Peter"); System.out.println("--------------------------"); SubClass subClassObj2 = new SubClass("John",30); } }
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.
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:
No comments:
Post a Comment