Re: reference objects (newbie question)
From: Roderik (ng_at_nl100.cjb.net)
Date: 11/28/03
- Next message: Mark Thornton: "Re: Advantages of 64-bit JVM"
- Previous message: Mohammed Mazid: "Gibberish output is display when returning an array"
- In reply to: Anthony Borla: "Re: reference objects (newbie question)"
- Next in thread: Jose Rubio: "Re: reference objects (newbie question)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 28 Nov 2003 23:33:57 +0100
On Fri, 28 Nov 2003 21:04:56 GMT, "Anthony Borla"
<ajborla@bigpond.com> wrote:
>
>"Roderik" <ng@nl100.cjb.net> wrote in message
>news:75cfsv48h80ukrmehsrpdtp4i5n8iqje0q@4ax.com...
>> Hi,
>>
>> I'd like to make a function to manipulate objects of a
>> given class.
>>
>> Let's say there are two objects, called MyPoint1
>> and MyPoint2. They are both of the class
>> cCustomPoint and contain an x an y attribute.
>>
>> The function should assign a value for x to a passed
>> object (MyPoint1 or MyPoint2).
>>
>
> class cCustomPoint
> {
> public int getX() { return x; }
> public int getY() { return y; }
> public int setX(int x) { this.x = x; }
> public int setY(int y) { this.y = y; }
>
> private int x, y;
> }
>
> class cCustomPointManager
> {
> ...
> public void passXTocCustomPoint(int x, cCustomPoint ccp)
> {
> ccp.setX(x);
> }
> ...
> }
>
> ...
> public static void main(String[] args)
> {
> ...
> cCustomPointManager ccpm = new cCustomPointManager();
> ...
> cCustomPoint MyPoint1 = new ..., MyPoint2 = new ...;
> ...
> ...
> ccpm.passXTocCustomPoint(5, MyPoint1);
> ccpm.passXTocCustomPoint(6, MyPoint2);
> ...
> ...
>
>>
>> How should I make this function so it knows which
>> object to manipulate and the value to be assigned?
>>
>
>I'm not sure what you are asking here. As the sample code [a very contrived
>example at that] shows, you normally know which object you want manipulated
>when you pass it as an argument to a method.
>
>I hope this helps [though you may need to rephrase your question]
>
>Anthony Borla
>
Yes, this is okay.
thanks a lot.
- Next message: Mark Thornton: "Re: Advantages of 64-bit JVM"
- Previous message: Mohammed Mazid: "Gibberish output is display when returning an array"
- In reply to: Anthony Borla: "Re: reference objects (newbie question)"
- Next in thread: Jose Rubio: "Re: reference objects (newbie question)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|