Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to reference the class-instance, created in parent class.

Status
Not open for further replies.

njava

Programmer
Aug 29, 2002
6
US
Hi, I have following scenario. During compilation I am gettting error message -- "cannot resolve symbol - symbol : Variable myZ"


CODE :
--------
under package A.1;
ClassZ
Servlet1
ClassZ myZ = new ClassZ;
under package A.2;
Servlet2 extends Servlet1
myZ.printHi();

How to reference the class-instance created in the parent class?

Thanks.
 
Have you set your CLASSPATH correctly and imported the relevant packages ?

--------------------------------------------------
Free Database Connection Pooling Software
 
Yup! I have..

Basically, I also have tried following cases --
I know that if i want to access some variable within super class then I would refer to that using "super." prefix.
Similarly, I would use the same "super" prefix to access any method defined within the parent class.

BUT, this is just a class LocalClass defined with in the package, in which parent class resides and just an instance is created within parent servlet (one time creation, as the instance creation is done in init method of parent servlet).

So, it does not help if i use super keyword!

Any clue?
 
When some class A extends class B, it means that A inherits B's behaviour at definition and compile time, but there's no link between two separate instances of classes A and B at runtime.

At runtime, if you have a as instance of A and b as instance of B you cannot access B's fields.

You should consider using static fields

Cheers,

Dian
 
...Post the code.

If myZ is an instance variable of ClassZ then you have to give it either a public or protected status in order for a subclass in a different package to see it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top