• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Simple issue of public variable

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Getting compile time error saying variable xx not found. Please help !

class th3
{
public int xx = 10;
public static void main(String s[])
{
proc p = new proc();
p.padd();
}
}

class proc
{
void padd()
{
System.out.println(xx);
}
}
 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

How are you tring to find the variable xx of class th3 in class proc?

You should have instance of class th3 or some other way to access the variable.
I would suggest you to read chapetr on scopes and varibles.

Regards
Sandeep Jindal
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi nitin

in your code you have two different classes, which are not related to each other in any way. if you want the variable xx to be accesed in other class you can either write :

"class <first class> extends <second class>

so that there is a relation established in them.
Otherwise the only option will be to create an instance of the other class and then access that variable through this object/instance.

bye
 
reply
    Bookmark Topic Watch Topic
  • New Topic