• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Questions on Mock Exam

 
Ranch Hand
Posts: 318
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, cowpokes...I just took the mock exam at javaprepare.com (Exam #1) and had these 2 questions that gave me trouble.
32.If a base class has a method defined as
void method() { }
Which of the following are legal prototypes in a derived class of this class.
Select all correct answers.
A.void method() { }
B.int method() { return 0;}
C.void method(int i) { }
D.private void method() { }
Answers are: A + C
(I don't understand why C is correct)

23.Which of the following are legal array declarations. Select all correct answers.
A.int i[5][];
B.int i[][];
C.int []i[];
D.int i[5][5];
E.int[][] a;
Answers are: B,C,E
(I don't understand why D is not correct)
Thanks for your help...
P.S. I DID scan the exam errata section and didn't see anything there...
Thanks,
Matt
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Matt DeLacey,

32.If a base class has a method defined as
void method() { }
Which of the following are legal prototypes in a derived class of this class.
Select all correct answers.
A.void method() { }
B.int method() { return 0;}
C.void method(int i) { }
D.private void method() { }
Answers are: A + C
(I don't understand why C is correct)

/* C is correct (I believe) because it is just overloading the constructor in the base class.*/
23.Which of the following are legal array declarations. Select all correct answers.
A.int i[5][];
B.int i[][];
C.int []i[];
D.int i[5][5];
E.int[][] a;
Answers are: B,C,E
(I don't understand why D is not correct)
/* D is not correct because you cannot declare the size of the array in this way. The proper way to declare it would be:
int []i[] = new int[5][5]
or...
int [][]i = new ...
or
int i[][] = new ...
You are not allowed to have anything within the hard braces on the left-hand side of the declaration; will produce a compile error. */
Regards,
Thomas
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question 1:
C is correct because this is a valid method overload, as opposed to B. In C, you are changing the number of arguments, so the compiler will know which method to call by the argument you pass in. But with B, the compiler is not going to know which mehtod to call by the return value, so that is why B is wrong.
Question 2:
Thomas is correct. Just remember that you can't construct an array on the left hand side, so the brackets always have to be empty on the left hand side. If they are empty, then they are probably right.
 
reply
    Bookmark Topic Watch Topic
  • New Topic