D
Dan
Here's a slightly altered bit of code from Sun's tutorial:
package instanceofdemo;
public class InstanceofDemo {
public InstanceofDemo() {
}
public static void main(String[] args) {
Parent obj1 = new Parent();
System.out.println("obj1 instanceof Parent: " + (obj1
instanceof Parent));
}
class Parent{
}
} //"Class End Brace"
The "Parent obj1 = new Parent();" line gets this error:
non-static variable this cannot be referenced from a static context
If I move the "Class End Brace" above the "class Parent{" line, the
error goes away.
I'm just on the edge of understanding why that should be. Can anyone
get me the rest of the way there? What's the compiler seeing that
causes this?
package instanceofdemo;
public class InstanceofDemo {
public InstanceofDemo() {
}
public static void main(String[] args) {
Parent obj1 = new Parent();
System.out.println("obj1 instanceof Parent: " + (obj1
instanceof Parent));
}
class Parent{
}
} //"Class End Brace"
The "Parent obj1 = new Parent();" line gets this error:
non-static variable this cannot be referenced from a static context
If I move the "Class End Brace" above the "class Parent{" line, the
error goes away.
I'm just on the edge of understanding why that should be. Can anyone
get me the rest of the way there? What's the compiler seeing that
causes this?