This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Sierra and Bates Master Exam Question Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Sierra and Bates Master Exam Question Question" Watch "Sierra and Bates Master Exam Question Question" New topic
Author

Sierra and Bates Master Exam Question Question

Billy Bob
Greenhorn

Joined: Apr 05, 2005
Posts: 21
Ok... just wrote the master exam offered on the Sierra and Bates "Sun Certified Programmer & Developer" Book... Scored fairly well but i have a couple of questions which are likely something fairly basic i'm missing...

------------------------------------------------------------------
Question: 1
Which two are valid method signatures in an interface? (Choose two.)
Correct Answer:
C: public void main(String [] wow);
E: boolean setFlag(Boolean [] test []);

EXPLANATION:
C and E are correct. These are valid interface method signatures.
A is incorrect because an interface method must be public; if it is not explicitly declared public it will be made public implicitly. B is incorrect because methods must have return types. D is incorrect because interface methods cannot be static.
--------------------------------------------------------------------

So the problem i am having is with the "B is incorrect because methods must have return types". There were three answers that I thought were possible. Those two and one that didn't have a return type (answer B). I was always under the impression that return types were optional, it was good practice to use void but it wasn't necessary. Is this a function of interfaces or is this just something that the IDE has always done for me and i'm just mistaken?

-----------------------------------------------------------------------

Question: 2
Given the following,
1. public class Test {
2. public static void main(String [] args) {
3. short [][] b = new short [4][4];
4. short [][] big = new short [2][2];
5. short b3 = 8;
6. short b2 [][][][] = new short [2][3][2][2];
7. // insert code here
8. }
9. }
which of the following lines of code could be inserted at line 7, and still allow the code to compile? (Choose four that would work.)
Correct Answer:
A: b2[1][1] = big;
B: b[1][0] = b3;
E: b2[1][1][0][1] = b[1][0];
F: b2[1][1] = b;
References:
EXPLANATION:
A, B, E, and F are correct. This question covers the issue of, "What can I assign to an array reference variable?" The key is to get the dimensions right. For example, if an array is declared as a two-dimensional array, you can't assign a one-dimensional array to a two-dimensional array reference. C is wrong because it tries to assign a two-dimensional array where a one-dimensional array is expected. D is wrong because it tries to assign a primitive short where a short array (one dimension) is expected.

-----------------------------------------------------------------------

With this question my problem is answer F. If you initialize a two dimensional array with 4 arrays of 4 short elements (0's by default) how can you then assign an initialized two dimensional (2 arrays of 2 short elements) array reference to it. I thought once those dimensions were there they were final, hence the reason we have collections. Or as the answer states is it just the dimensions that are fixed and the number of elements in each can change?


Any help would be appreciated as i write this puppy on monday.

thx
Giovanni De Stefano
Ranch Hand

Joined: Aug 17, 2004
Posts: 144
Hi Billy Bob,

Question 1. in Java the return type is NOT optional!!! YOU MUST write a return type, in C you can omit it (even if some 'good' compilers pretend you to write one.


SCJP 1.4
Giovanni De Stefano
Ranch Hand

Joined: Aug 17, 2004
Posts: 144
Hi Billy Bob,

Question 2. This is what you have:
short [][] b = new short [4][4];
short b2 [][][][] = new short [2][3][2][2];

in Java what counts is NOT the LENGTH of an array but its DIMENSION, so:
b2[0] -> [][][]
b2[0][0] -> [][]
b -> [][]

then b2[0][0] = b is CORRECT.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sierra and Bates Master Exam Question Question
 
Similar Threads
Array Reference Assignments
Arrays
Master Exam Array question
Multi-dim Array
Reg :- Java Multi Dimension Array