Created
June 9, 2015 08:17
-
-
Save sermojohn/efe1f5177e5393e67212 to your computer and use it in GitHub Desktop.
NestedClassesTest
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
package ocp; | |
/** Static methods of hierarchy classes are called on the reference variable type. */ | |
public class NestedClassTest { | |
/** Nested classes need to be static in order to define static methods (Nested class, not Inner) */ | |
static class A { | |
public void parentMethod() { | |
System.out.println("parent method"); | |
} | |
public static void someMethod() { | |
System.out.println("A method"); | |
} | |
} | |
static class B extends A { | |
public static void someMethod() { | |
System.out.println("B method"); | |
} | |
} | |
static class C extends B { | |
public static void someMethod() { | |
System.out.println("C method"); | |
} | |
} | |
public static void main(String args[]) { | |
C c = new C(); | |
c.someMethod(); | |
c.parentMethod(); | |
B b = c; | |
b.someMethod(); | |
b.parentMethod(); | |
A a = b; | |
a.someMethod(); | |
a.parentMethod(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
C method
parent method
B method
parent method
A method
parent method