"JavaRanch, where the deer and the Certified play" - David O'Meara
Originally posted by Cindy Glass:
Well. . . . I don't know where to start.
First of all the t.guy syntax that you are using would only be correct if there were a method in the avi class named guy(). You cannot invoke a CLASS on anything, and in your example the guy class is completely unrelated to the avi class.
Then, the guy class has not return type, but you do a return anyway. Perhaps you were thinking of having a method in the guy class to return something??? Or perhaps you meant to have a main method in the class???
Then, when you return this.a you are using the term "this" to distinguish it (normally) from it's super, but guy has no super so it is un-needed.
If you want to be able to say guy.a and have it equal 45 then you need to make the variable "a" a static (class level) variable which of course means that there IS NO "this.a" at all. Otherwise you need to make an instance of guy:
guy g = new guy();
and reference g.a (the "a" varible that belongs to g).
I don't know if I have cleared anything up or just made it muddier.
"JavaRanch, where the deer and the Certified play" - David O'Meara
Originally posted by Cindy Glass:
Not to be a stickler - but NOTHING in java is a pointer. Object variables use references (not to be confused with pointers), but variables that are primitives hold the actual value not a reference value.
If you have many objects created, and all of them have their own primitive variable "a", and you need to clarify which objects "a" that you are looking at you use "<object variable name>.a" (this is typically used in a main() method or something).
If you are coding a class (as opposed to using a class) and you want to do something to the "a" of whatever object gets created using the class then you use the "this.a" syntax.
"JavaRanch, where the deer and the Certified play" - David O'Meara
Consider Paul's rocket mass heater. |