Created
September 3, 2017 15:57
-
-
Save LazaroIbanez/af73a76136717169a9002361b6bc047e to your computer and use it in GitHub Desktop.
super java example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class G extends G1 { | |
int x = 100; | |
public void display() { | |
System.out.println(“Subclass x value: “ + x); // prints 100 | |
System.out.println(“Super class x value: “ + super.x); // prints 10 | |
System.out.println(“Sum of x values: “ + (x + super.x)); // prints 110 | |
super.display(); // calling super class (G1) display() | |
System.out.println(“From subclass”); | |
} | |
public static void main(String args[]) { | |
G objectG = new G(); | |
objectG.display(); | |
} | |
} | |
class G1 { | |
int x = 10; | |
public void display() { | |
System.out.println(“From super class”); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment