super keyword
This commit is contained in:
		
							parent
							
								
									477bb63e21
								
							
						
					
					
						commit
						027f011e67
					
				| @ -1,5 +1,6 @@ | ||||
| package com.baeldung.keyword; | ||||
| 
 | ||||
| import com.baeldung.keyword.superkeyword.SubClass; | ||||
| import com.baeldung.keyword.thiskeyword.ThisKeyword; | ||||
| 
 | ||||
| /** | ||||
| @ -9,5 +10,7 @@ public class KeywordDemo { | ||||
| 
 | ||||
|     public static void main(String[] args) { | ||||
|         ThisKeyword keyword = new ThisKeyword(); | ||||
| 
 | ||||
|         SubClass child = new SubClass("message from the child class"); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -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); | ||||
|     } | ||||
| } | ||||
| @ -4,4 +4,17 @@ package com.baeldung.keyword.superkeyword; | ||||
|  * Created by Gebruiker on 5/14/2018. | ||||
|  */ | ||||
| public class SuperKeyword { | ||||
| 
 | ||||
|     String message = "super class"; | ||||
| 
 | ||||
|     public SuperKeyword() { | ||||
|     } | ||||
| 
 | ||||
|     public SuperKeyword(String message) { | ||||
|         this.message = message; | ||||
|     } | ||||
| 
 | ||||
|     public void printMessage() { | ||||
|         System.out.println(message); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -31,8 +31,15 @@ public class ThisKeyword { | ||||
|         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 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user