this keyword
This commit is contained in:
parent
4d800396b8
commit
477bb63e21
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.baeldung.keyword.superkeyword;
|
||||
|
||||
/**
|
||||
* Created by Gebruiker on 5/14/2018.
|
||||
*/
|
||||
public class SuperKeyword {
|
||||
}
|
|
@ -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 +
|
||||
'}';
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue