Merge pull request #4265 from MherBaghinyan/BAEL-1788

Bael 1788
This commit is contained in:
Eric Martin 2018-05-29 22:35:11 -05:00 committed by GitHub
commit 523fbf433c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 111 additions and 0 deletions

View File

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

View File

@ -0,0 +1,20 @@
package com.baeldung.keyword.superkeyword;
/**
* Created by Gebruiker on 5/14/2018.
*/
public class SuperBase {
String message = "super class";
public SuperBase() {
}
public SuperBase(String message) {
this.message = message;
}
public void printMessage() {
System.out.println(message);
}
}

View File

@ -0,0 +1,26 @@
package com.baeldung.keyword.superkeyword;
/**
* Created by Gebruiker on 5/15/2018.
*/
public class SuperSub extends SuperBase {
String message = "child class";
public SuperSub(String message) {
super(message);
}
public SuperSub() {
super.printMessage();
printMessage();
}
public void getParentMessage() {
System.out.println(super.message);
}
public void printMessage() {
System.out.println(message);
}
}

View File

@ -0,0 +1,49 @@
package com.baeldung.keyword.thiskeyword;
public class KeywordTest {
private String name;
private int age;
public KeywordTest() {
this("John", 27);
this.printMessage();
printInstance(this);
}
public KeywordTest(String name, int age) {
this.name = name;
this.age = age;
}
public void printMessage() {
System.out.println("invoked by this");
}
public void printInstance(KeywordTest thisKeyword) {
System.out.println(thisKeyword);
}
public KeywordTest getCurrentInstance() {
return this;
}
class ThisInnerClass {
boolean isInnerClass = true;
public ThisInnerClass() {
KeywordTest thisKeyword = KeywordTest.this;
String outerString = KeywordTest.this.name;
System.out.println(this.isInnerClass);
}
}
@Override
public String toString() {
return "KeywordTest{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
}