Skip to content

Instantly share code, notes, and snippets.

@LazaroIbanez
Created September 3, 2017 15:57
Show Gist options
  • Save LazaroIbanez/af73a76136717169a9002361b6bc047e to your computer and use it in GitHub Desktop.
Save LazaroIbanez/af73a76136717169a9002361b6bc047e to your computer and use it in GitHub Desktop.
super java example
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