super keyword

This commit is contained in:
mherbaghinyan 2018-05-16 17:03:42 +04:00
parent 477bb63e21
commit 027f011e67
4 changed files with 50 additions and 1 deletions

View File

@ -1,5 +1,6 @@
package com.baeldung.keyword; package com.baeldung.keyword;
import com.baeldung.keyword.superkeyword.SubClass;
import com.baeldung.keyword.thiskeyword.ThisKeyword; import com.baeldung.keyword.thiskeyword.ThisKeyword;
/** /**
@ -9,5 +10,7 @@ public class KeywordDemo {
public static void main(String[] args) { public static void main(String[] args) {
ThisKeyword keyword = new ThisKeyword(); ThisKeyword keyword = new ThisKeyword();
SubClass child = new SubClass("message from the child class");
} }
} }

View File

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

View File

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

View File

@ -31,8 +31,15 @@ public class ThisKeyword {
return this; return this;
} }
class ThiInnerClass { class ThisInnerClass {
boolean isInnerClass = true;
public ThisInnerClass() {
ThisKeyword thisKeyword = ThisKeyword.this;
String outerString = ThisKeyword.this.name;
System.out.println(this.isInnerClass);
}
} }
@Override @Override