Skip to content

Instantly share code, notes, and snippets.

@dapurv5
Created June 12, 2015 09:55
Show Gist options
  • Save dapurv5/3d3926b724021953dd06 to your computer and use it in GitHub Desktop.
Save dapurv5/3d3926b724021953dd06 to your computer and use it in GitHub Desktop.
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