Created
June 12, 2015 09:55
-
-
Save dapurv5/3d3926b724021953dd06 to your computer and use it in GitHub Desktop.
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
class Base { | |
static int x = 0; | |
int m = 0; | |
} | |
class Derived extends Base | |
{ | |
static int x = 2; | |
int m = 3; | |
public static void fun() { | |
System.out.println(x); // Compiler Error: non-static variable | |
// cannot be referenced from a static context | |
} | |
public void fun2() { | |
System.out.println(m); | |
} | |
} | |
/** | |
* @author dapurv5 | |
*/ | |
public class InheritanceDemo { | |
public static void main(String[] args) { | |
Derived d = new Derived(); | |
Derived.fun(); | |
d.fun2(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment