File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt on Marcus Green's Mock Answers

 
Denise Advincula
Ranch Hand
Posts: 163
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Ankit Garg
Sheriff
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
#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--.
 
Vijitha Kumara
Bartender
Posts: 3908
9
Chrome Fedora Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
Marcus Green
arch rival
Rancher
Posts: 2813
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic