File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes confused Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "confused" Watch "confused" New topic


saied ims
Ranch Hand

Joined: Jun 21, 2005
Posts: 109
1. public class CommandArgsThree {
2. public static void main(String [] args) {
3. String [][] argCopy = new String[2][2];
4. int x;
5. argCopy[0] = args;
6. x = argCopy[0].length;
7. for (int y = 0; y < x; y++) {
8. System.out.print(" " + argCopy[0][y]);
9. }
10. }
11. }
the answer is :
D. In line 5, the reference variable argCopy[0], which was referring to an array with
two elements, is reassigned to an array (args) with three elements
how did assign array of 2 elements to array of 3
vidya sagar
Ranch Hand

Joined: Mar 02, 2005
Posts: 580

argCopy[0] = args;
how did assign array of 2 elements to array of 3

args is one dimensional array
argcopy is two dimensional array

argcopy[0] can have address of single dimensional array or null
argcopy[0][0] can have values

argCopy[0] = args;
In our case we are having address of args to argcopy
[i.e address of one dimensional array to argcopy[0]]
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Referring to the first post: What is the full question?

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Arulkumar Gopalan
Ranch Hand

Joined: Oct 13, 2003
Posts: 104

Actual Question:
how did assign array of 2 elements to array of 3

Q should have been: how did assign array of 3 elements to array of 2?

Q could be: Size of one dimensional array(args) is greater than size created for the first row of two dimensional array(argCopy[0]). How does it work?

Anbudan & Mahalo,<br />Arul<br /> <br />-Not a sun certified Java professional :-)
I agree. Here's the link:
subject: confused
It's not a secret anymore!