Skip to content

Instantly share code, notes, and snippets.

@kenorb
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save kenorb/bbc6b4e24c92806bac3e to your computer and use it in GitHub Desktop.

Select an option

Save kenorb/bbc6b4e24c92806bac3e to your computer and use it in GitHub Desktop.
Super Demo in Java.
/*
* Super Demo.
*
* super() is used to access members of superclass.
*/
class A {
int x = 1000;
void display() {
System.out.println(x);
}
}
class B extends A {
int x = 2000;
void display() { // Overriden method.
System.out.println(x); // Invokes local member.
System.out.println(super.x); // Invokes superclass member.
super.display(); // Invokes display from class A.
}
}
class Super {
public static void main(String[] args) {
B b1 = new B();
b1.display();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment