Saturday 15 January 2011

symbol - How do I access a class variable in another class? -


Java Noble here completely. Currently teaching myself lately, I tried to create a basic program that would use a class to get information from other classes, and print it. I keep getting this error:

  The error symbol can not find the system. Out.print1n (ljames.weight); Symbol: Variable Weight Location: Class ljames   

Here's my code:

Please help me.

I think this is only the visibility of the variable

Declared to the public, they are accessible from somewhere else.

I recommend making each other a public developer and access-accessories for their variables. You set them through constructor and read them through access-accessor. This way you can keep your data safe and you can change even when you need it.

  class data {string height; Visceral weight; Int depth; Public Data (String Height, Intimate Weight, Inner Depth) {this.height = height; this. Weight = weight; This.depth = Depth; } Public string getHeight () {return height; } Public int getWeight () {return weight; } Public int getDepth () {return depth; }}    

No comments:

Post a Comment