File tree Expand file tree Collapse file tree
core-java/src/main/java/com/baeldung/keyword Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .baeldung .keyword ;
2+
3+ import com .baeldung .keyword .superkeyword .SuperSub ;
4+ import com .baeldung .keyword .thiskeyword .KeywordTest ;
5+
6+ /**
7+ * Created by Gebruiker on 5/14/2018.
8+ */
9+ public class KeywordDemo {
10+
11+ public static void main (String [] args ) {
12+ KeywordTest keyword = new KeywordTest ();
13+
14+ SuperSub child = new SuperSub ("message from the child class" );
15+ }
16+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .keyword .superkeyword ;
2+
3+ /**
4+ * Created by Gebruiker on 5/14/2018.
5+ */
6+ public class SuperBase {
7+
8+ String message = "super class" ;
9+
10+ public SuperBase () {
11+ }
12+
13+ public SuperBase (String message ) {
14+ this .message = message ;
15+ }
16+
17+ public void printMessage () {
18+ System .out .println (message );
19+ }
20+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .keyword .superkeyword ;
2+
3+ /**
4+ * Created by Gebruiker on 5/15/2018.
5+ */
6+ public class SuperSub extends SuperBase {
7+
8+ String message = "child class" ;
9+
10+ public SuperSub (String message ) {
11+ super (message );
12+ }
13+
14+ public SuperSub () {
15+ super .printMessage ();
16+ printMessage ();
17+ }
18+
19+ public void getParentMessage () {
20+ System .out .println (super .message );
21+ }
22+
23+ public void printMessage () {
24+ System .out .println (message );
25+ }
26+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .keyword .thiskeyword ;
2+
3+ public class KeywordTest {
4+
5+ private String name ;
6+ private int age ;
7+
8+ public KeywordTest () {
9+ this ("John" , 27 );
10+ this .printMessage ();
11+ printInstance (this );
12+ }
13+
14+ public KeywordTest (String name , int age ) {
15+ this .name = name ;
16+ this .age = age ;
17+ }
18+
19+ public void printMessage () {
20+ System .out .println ("invoked by this" );
21+ }
22+
23+ public void printInstance (KeywordTest thisKeyword ) {
24+ System .out .println (thisKeyword );
25+ }
26+
27+ public KeywordTest getCurrentInstance () {
28+ return this ;
29+ }
30+
31+ class ThisInnerClass {
32+
33+ boolean isInnerClass = true ;
34+
35+ public ThisInnerClass () {
36+ KeywordTest thisKeyword = KeywordTest .this ;
37+ String outerString = KeywordTest .this .name ;
38+ System .out .println (this .isInnerClass );
39+ }
40+ }
41+
42+ @ Override
43+ public String toString () {
44+ return "KeywordTest{" +
45+ "name='" + name + '\'' +
46+ ", age=" + age +
47+ '}' ;
48+ }
49+ }
You can’t perform that action at this time.
0 commit comments