ThisKeyword -> KeywordTest

This commit is contained in:
mherbaghinyan 2018-05-27 10:22:30 +04:00
parent 969f40da6e
commit bc4690ee54
2 changed files with 10 additions and 13 deletions

View File

@ -1,7 +1,7 @@
package com.baeldung.keyword; package com.baeldung.keyword;
import com.baeldung.keyword.superkeyword.SuperSub; import com.baeldung.keyword.superkeyword.SuperSub;
import com.baeldung.keyword.thiskeyword.ThisKeyword; import com.baeldung.keyword.thiskeyword.KeywordTest;
/** /**
* Created by Gebruiker on 5/14/2018. * Created by Gebruiker on 5/14/2018.
@ -9,7 +9,7 @@ import com.baeldung.keyword.thiskeyword.ThisKeyword;
public class KeywordDemo { public class KeywordDemo {
public static void main(String[] args) { public static void main(String[] args) {
ThisKeyword keyword = new ThisKeyword(); KeywordTest keyword = new KeywordTest();
SuperSub child = new SuperSub("message from the child class"); SuperSub child = new SuperSub("message from the child class");
} }

View File

@ -1,20 +1,17 @@
package com.baeldung.keyword.thiskeyword; package com.baeldung.keyword.thiskeyword;
/** public class KeywordTest {
* Created by Gebruiker on 5/14/2018.
*/
public class ThisKeyword {
private String name; private String name;
private int age; private int age;
public ThisKeyword() { public KeywordTest() {
this("John", 27); this("John", 27);
this.printMessage(); this.printMessage();
printInstance(this); printInstance(this);
} }
public ThisKeyword(String name, int age) { public KeywordTest(String name, int age) {
this.name = name; this.name = name;
this.age = age; this.age = age;
} }
@ -23,11 +20,11 @@ public class ThisKeyword {
System.out.println("invoked by this"); System.out.println("invoked by this");
} }
public void printInstance(ThisKeyword thisKeyword) { public void printInstance(KeywordTest thisKeyword) {
System.out.println(thisKeyword); System.out.println(thisKeyword);
} }
public ThisKeyword getCurrentInstance() { public KeywordTest getCurrentInstance() {
return this; return this;
} }
@ -36,15 +33,15 @@ public class ThisKeyword {
boolean isInnerClass = true; boolean isInnerClass = true;
public ThisInnerClass() { public ThisInnerClass() {
ThisKeyword thisKeyword = ThisKeyword.this; KeywordTest thisKeyword = KeywordTest.this;
String outerString = ThisKeyword.this.name; String outerString = KeywordTest.this.name;
System.out.println(this.isInnerClass); System.out.println(this.isInnerClass);
} }
} }
@Override @Override
public String toString() { public String toString() {
return "ThisKeyword{" + return "KeywordTest{" +
"name='" + name + '\'' + "name='" + name + '\'' +
", age=" + age + ", age=" + age +
'}'; '}';