my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt on Marcus Green's Mock Answers 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 "Doubt on Marcus Green Watch "Doubt on Marcus Green New topic
Author

Doubt on Marcus Green's Mock Answers

Denise Advincula
Ranch Hand

Joined: Jan 01, 2007
Posts: 160
These questions are from Marcus Green's Mock Exam


Question 42)
Given the following declaration

Integer i=new Integer(99);

How can you now set the value of i to 10?

1) i=10;
2) i.setValue(10);
3) i.parseInt(10);
4) none of the above

Answer to Question 42)

Objective 4.6)

4) none of the above

The wrapper classes are immutable. Once the value has been set it cannot be changed. A common use of the wrapper classes is to take advantage of their static methods such as Integer.parseInt(String s) that will returns an integer if the the value has been set it cannot be changed. A common use of the wrapper classes is to take advantage of their static methods such as Integer.parseInt(String s) that will returns an integer if the String contains one.

I actually have no doubts here. I just couldn't get the idea of wrappers being immutable yet (I'm having some confusions).


Question 46)

Which of the following statements are true?

1) A method cannot be overloaded to be less public in a child class
2) To be overridden a method only needs the same name and parameter types
3) To be overridden a method must have the same name, parameter and return types
4) An overridden method must have the same name, parameter names and parameter types

Answer to Question 46)

Objective 6.2)

3) To be overriden a method must have the same name, parameter and return types

Option 1 is a sneaky one in that it should read overriden not overloaded. An overriden method must also have the same return type. Parameter names are purely a programmer convenience and are not a factor in either overloading and overriding. Parameter order is a factor however.

My answer here is 2. Because as of 1.5, return type can change to a subclass of the original method's return type (covariant returns). Is this correct?


Question 56)
Given the following class

public class ZeroPrint{
public static void main(String argv[]){
int i =0;
//Here
}
}

Which of the following lines if placed after the comment //Here will print out 0.

1) System.out.println(i++);
2) System.out.println(i+'0');
3) System.out.println(i);
4) System.out.println(i--);

Answer to Question 56)

Objective 5.1)

1) System.out.println(i++);
3) System.out.println(i);
4) System.out.println(i==);

The options for this question might look suspiciously easy if you are not aware of the effects of the post-increment operators. The ++ and == operations for examples 1 and 4 only come into effect after the output operations, ie after whatever else is done to them on that line of code. Option 2 should be fairly obvious as you should know that the single quote characters indicate a char value, ie storing the character rather than the numberical value for 0.


My answer is 1 and 3. Is this a typo error? Because option 4 differs in the Question and the Answer page.

I hope you can help me clarify these. THank you!


SCJP/OCPJP 6 | SCWCD/OCPJWCD 5 | OCMJEA in progress...
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

#1
i = 10 is correct. Actually I think the exam is for SCJP 1.2 or 1.4. So there was no autoboxing at that time.

#2
again the exam is old so it does not considers covariant return types.

#3 yes this is a typing mistake. The 3rd option is i--.


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3833

Answer to Question 46)

My answer here is 2. Because as of 1.5, return type can change to a subclass of the original method's return type (covariant returns). Is this correct?


Yes that's possible. But the answer says

To be overridden a method only needs the same name and parameter types


Here it gives the impression that you can use anything for the return type. But actually you can use only subtypes .


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Marcus Green
arch rival
Rancher

Joined: Sep 14, 1999
Posts: 2813
Thank you for your comments and in particular quoting my answers (something people often forget to do). I will look more closely at your questions when I am not at work.

Marcus
[ September 11, 2008: Message edited by: Marcus Green ]

SCWCD: Online Course, 50,000+ words and 200+ questions
http://www.examulator.com/moodle/course/view.php?id=5&topic=all
 
GeeCON Prague 2014
 
subject: Doubt on Marcus Green's Mock Answers