Last active
August 29, 2015 14:04
-
-
Save kenorb/bbc6b4e24c92806bac3e to your computer and use it in GitHub Desktop.
Super Demo in Java.
This file contains hidden or 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
| /* | |
| * 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