wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes chapter 5,question-8,(k&b) 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 "chapter 5,question-8,(k&b)" Watch "chapter 5,question-8,(k&b)" New topic
Author

chapter 5,question-8,(k&b)

Sambit Banerjee
Greenhorn

Joined: Jul 29, 2008
Posts: 18

i think line 7 needs some modification,the arg in Integer.parseInt() should be in double quotes.and barring option b all the options seem to be right but in the answer it is given only options a and c are correct.
please check this and reply.
Jiang zhixiao
Greenhorn

Joined: Jul 01, 2008
Posts: 13
public static int parseInt(String s)
throws NumberFormatException

return int,any questions?
Sambit Banerjee
Greenhorn

Joined: Jul 29, 2008
Posts: 18
jiang,sorry i could not get you.please discuss it in a bit details.
Pranav Bhatt
Ranch Hand

Joined: Mar 20, 2006
Posts: 284
Sambit,
Why do you think it should be in double quotes? arg is already in String format though its a number, thats why you need to parse it for int. One more thing you have not posted the option so people here wont be able to identify the correct ones
[ September 02, 2008: Message edited by: Pranav Bhatt ]
ankit kumar
Ranch Hand

Joined: Apr 28, 2008
Posts: 108
class Ping extends Utils {
public static void main(String [] args) {
Utils uu = new Ping();
System.out.print(uu.getInt(args[0]));
}
int getInt(String arg) {
return Integer.parseInt(arg);
}
}
class Utils {
int getInt(String x) throws Exception { return 7; }
}
And the following three possible changes:
C1. Declare that main() throws an Exception.
C2. Declare that Ping.getInt() throws an Exception.
C3. Wrap the invocation of getInt() in a try / catch block.
Which change(s) allow the code to compile? (Choose all that apply.)
A. Just C1 is sufficient.
B. Just C2 is sufficient.
C. Just C3 is sufficient.
D. Both C1 and C2 are required.
E. Both C1 and C3 are required.
F. Both C2 and C3 are required.
G. All three changes are required.


and the ans is A&C


Cleared SCJP 1.5 | Cleared SCWCD 5.0
SCDJWS 6 in progress.....
Sambit Banerjee
Greenhorn

Joined: Jul 29, 2008
Posts: 18
@ pranav,
actually i was getting the follwing compiler error:
Ping.java.18:cannot find symbol
symbol:method parseInt(String)
location:class java.lang.Integer
return Integer.parseInt(arg);
1 error.
so i thought that double quotes should be used.
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8879
    
    5
Hey Sambit,

What's the version of the compiler you are using?


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Sambit Banerjee
Greenhorn

Joined: Jul 29, 2008
Posts: 18
@ bert,
its jdk1.6.0_07.
Sambit Banerjee
Greenhorn

Joined: Jul 29, 2008
Posts: 18
can anyone tell me anything about the confusion.
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8879
    
    5
Sambit -

I think you should post your EXACT CODE!

Thanks,

Bert
Sambit Banerjee
Greenhorn

Joined: Jul 29, 2008
Posts: 18
Bert,as you have asked for my jdk version i thought i have a problem with it.So,i have checked it in my friend's pc and i found no problem with Integer.parseInt(arg).
But i have checked the options also and still find that except option b all the options compile the code.
Here's the exact code.

Puneet Nahata
Greenhorn

Joined: Aug 30, 2008
Posts: 9
I think you are confused with the options. D,E,F,G are not possible.
Consider option E. It says "Both C1 and C3 are required". But actually either of them will suffice(though there is no harm if you apply both options while testing in code. It will work fine.)


Originally posted by Sambit Banerjee:
Bert,as you have asked for my jdk version i thought i have a problem with it.So,i have checked it in my friend's pc and i found no problem with Integer.parseInt(arg).
But i have checked the options also and still find that except option b all the options compile the code.
Here's the exact code.



do not anger the GODS.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: chapter 5,question-8,(k&b)