this keyword

This commit is contained in:
mherbaghinyan 2018-05-14 18:59:29 +04:00
parent 4d800396b8
commit 477bb63e21
3 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,13 @@
package com.baeldung.keyword;
import com.baeldung.keyword.thiskeyword.ThisKeyword;
/**
* Created by Gebruiker on 5/14/2018.
*/
public class KeywordDemo {
public static void main(String[] args) {
ThisKeyword keyword = new ThisKeyword();
}
}

View File

@ -0,0 +1,7 @@
package com.baeldung.keyword.superkeyword;
/**
* Created by Gebruiker on 5/14/2018.
*/
public class SuperKeyword {
}

View File

@ -0,0 +1,45 @@
package com.baeldung.keyword.thiskeyword;
/**
* Created by Gebruiker on 5/14/2018.
*/
public class ThisKeyword {
private String name;
private int age;
public ThisKeyword() {
this("John", 27);
this.printMessage();
printInstance(this);
}
public ThisKeyword(String name, int age) {
this.name = name;
this.age = age;
}
public void printMessage() {
System.out.println("invoked by this");
}
public void printInstance(ThisKeyword thisKeyword) {
System.out.println(thisKeyword);
}
public ThisKeyword getCurrentInstance() {
return this;
}
class ThiInnerClass {
}
@Override
public String toString() {
return "ThisKeyword{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
}