diff --git a/core-java/src/main/java/com/baeldung/keyword/KeywordDemo.java b/core-java/src/main/java/com/baeldung/keyword/KeywordDemo.java new file mode 100644 index 0000000000..d98586c233 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/keyword/KeywordDemo.java @@ -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"); + } +} diff --git a/core-java/src/main/java/com/baeldung/keyword/superkeyword/SuperBase.java b/core-java/src/main/java/com/baeldung/keyword/superkeyword/SuperBase.java new file mode 100644 index 0000000000..a5304fcef9 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/keyword/superkeyword/SuperBase.java @@ -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); + } +} diff --git a/core-java/src/main/java/com/baeldung/keyword/superkeyword/SuperSub.java b/core-java/src/main/java/com/baeldung/keyword/superkeyword/SuperSub.java new file mode 100644 index 0000000000..83bc04ad0f --- /dev/null +++ b/core-java/src/main/java/com/baeldung/keyword/superkeyword/SuperSub.java @@ -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); + } +} diff --git a/core-java/src/main/java/com/baeldung/keyword/thiskeyword/KeywordTest.java b/core-java/src/main/java/com/baeldung/keyword/thiskeyword/KeywordTest.java new file mode 100644 index 0000000000..8c6adcfc50 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/keyword/thiskeyword/KeywordTest.java @@ -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 + + '}'; + } +}