newbie java/OOP question  
Author Message
Mike0000





PostPosted: 2003-10-7 13:13:00 Top

java-programmer, newbie java/OOP question Perhaps someone here can help me with this, I tried asking someone else
about this but couldn't quite describe my question.

I understand that this syntax calls a method on behalf of an object:

b1.method();

but in some java example code I see stuff like this (from a link list app) :

answer.head = IntNode.listCopy(head);

I know that "head" is an instance variable of the class, specfically an
IntNode. I also know that "answer" is a method variable of the type
IntLinkedBag.

My question is: what the heck is going on during the "answer.head"
operation? I don't understand how answer is interacting with head.
They're just two objects. What does the period do when it connects two
objects?

Any pointers or keywords to look up would be apprecited.

--
Mike
Block Banner Ads Now
http://everythingisnt.com/hosts.html

 
Paul





PostPosted: 2003-10-7 14:41:00 Top

java-programmer >> newbie java/OOP question Mike0000 wrote:
> Perhaps someone here can help me with this, I tried asking someone else
> about this but couldn't quite describe my question.
>
> I understand that this syntax calls a method on behalf of an object:
>
> b1.method();
>
> but in some java example code I see stuff like this (from a link list
> app) :
>
> answer.head = IntNode.listCopy(head);
>
> I know that "head" is an instance variable of the class, specfically an
> IntNode. I also know that "answer" is a method variable of the type
> IntLinkedBag.
>
> My question is: what the heck is going on during the "answer.head"
> operation? I don't understand how answer is interacting with head.
> They're just two objects. What does the period do when it connects two
> objects?
>

I'm a relative newbie too but this is the way I understand it.

From what you say answer is an object of the class IntLinkedBag. If you
look at the class IntLinkedBag you should find it has an attribute (or
data field) called head. So "answer.head =" is just setting the value of
this attribute.

listCopy(head) is a class method of the class IntNode. Its argument (or
parameter) is head. This is probably not the same object as answer.head.

BTW the dot just signifies that the second object is an attribute of the
first.

Hope that helps.

Paul

 
Joe





PostPosted: 2003-10-7 23:50:00 Top

java-programmer >> newbie java/OOP question In article <KXrgb.696238$Ho3.153115@sccrnsc03>,
email***@***.com says...

> answer.head = IntNode.listCopy(head);
>
>
> Any pointers or keywords to look up would be apprecited.


My first impression is that the example code is an example of very bad
OOP. Obviously I haven't seen the whole example and I could be wrong, but
from that single line, it appears as if the author is porting an example
in C directly over to Java. If you're having difficulty understanding it,
perhaps you should google a different example of a linked list
implementation and see if that makes better sense.






---
"War is God's way of teaching Americans geography"

-- Ambrose Bierce