It's not a secret anymore!
The moose likes Java in General and the fly likes clone help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "clone help" Watch "clone help" New topic

clone help

indi anj

Joined: Sep 11, 2005
Posts: 5
i was reading java book and i did not get the clone part.

int [] p = new int [100];
int [] s = (int[]) p.clone();

Which of the following statements will change the last value of p to 75?

A) p[99]=75; B)p[100]=75; C)s[99]=75; D)s[100]=75; E) two or more of the answers will chane i to 75
[ September 11, 2005: Message edited by: indi anj ]
Stuart Gray
Ranch Hand

Joined: Apr 21, 2005
Posts: 410
Sorry, what exactly is the question?
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
It seems that part of the question is missing. The choices given don't make any sense based on the code snippet that you gave. I know it probably isn't part of your question, but it will help us understand the context so that we can provide an answer.

[ September 11, 2005: Message edited by: Layne Lund ]

Java API Documentation
The Java Tutorial
shank ram

Joined: Sep 05, 2005
Posts: 22
The question you have posed analyses your grasp of fundamental array concepts.

The last element of a array 'p' of 100 integer elements is addressed as what ... p[100] or p[99] ? - This is the first point to be understood.

After you successfully cloned the array 'p' ... will the change in an element of the clone ... here 's' ... reflect on the original 'p' ? - This is the second point.

So, write the code

Hope this helps.
I agree. Here's the link:
subject: clone help
It's not a secret anymore!