how to over come this cannot be referenced n cannot find

February 23, 2012 at 01:04:08
Specs: Windows XP
class ParentClass
{
void display()
{
System.out.println("parent display");
}
}
class ChildClass extends ParentClass
{
void display()
{
System.out.println("Child display");
}
void display(int x)
{
System.out.println("X:" +x);
}
}
class SingleInherit
{
public static void main(String args[])
{
ChildClass cc = new ChildClass();
super.display();
cc.display();
cc.display(10);
//ChildClass cc1 = new ParentClass();
//super.display();
}


C:\Program Files\java\jdk1.5.0_05\bin>javac SingleInherit.java
SingleInherit.java:24: non-static variable super cannot be referenced from a sta
tic context
super.display();
^
SingleInherit.java:24: cannot find symbol
symbol : method display()
location: class java.lang.Object
super.display();
^
2 errors


See More: how to over come this cannot be referenced n cannot find

Report •

#1
February 23, 2012 at 01:18:57
You are not using "super" in the way you intend. If it worked (and the error message explains why it does not) you would be invoking the "display" method of "Object" (which is the SuperClass of "SingleInherit", whereas you mean to invoked the method of "ParentClass".

The error itself (although irrelevant) is that "main" is a static class method whereas "super" specifies an instance. You can't invoke a class method on an instance variable.


Report •
Related Solutions


Ask Question