Click here to watch in Youtube :
https://www.youtube.com/watch?v=1LFy7M6vEbs&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
Java Tutorial : Java this keyword (access constructors) |
public class Student { public String name; public int age; public Student() { this("David", 45); } public Student(String name) { this(name, 45); } public Student(String name, int age) { this.name = name; this.age = age; } }
public class StudentTest { public static void main(String[] args) throws InterruptedException { Student student1 = new Student(); System.out.println("name : " + student1.name); System.out.println("age : " + student1.age); System.out.println("-----------------------------"); Student student2 = new Student("John"); System.out.println("name : " + student2.name); System.out.println("age : " + student2.age); } }
name : David age : 45 ----------------------------- name : John age : 45
https://sites.google.com/site/javaee4321/java/ThisKeyWordDemoConstructorsApp.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/ThisKeyWordDemoConstructorsApp
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/f95cef6f929a55d126484d6f51e7b129a718c586/BasicJava/ThisKeyWordDemoConstructorsApp/?at=master
See also:
No comments:
Post a Comment