• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Doubt on Marcus Green's Mock Answers

 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Sheriff
Posts: 9693
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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--.
 
Bartender
Posts: 4109
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic