Wednesday 16 December 2015

Java Tutorial : Java this keyword (access constructors)


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)
Student.java
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;
    }

}
StudentTest.java
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);

    }

}
Output
name : David
age  : 45
-----------------------------
name : John
age  : 45

Click the below link to download the code:
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:

  • 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