permaculture playing cards*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question from Marcus Green's exam 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 "Question from Marcus Green Watch "Question from Marcus Green New topic
Author

Question from Marcus Green's exam

geeta rai
Ranch Hand

Joined: Sep 18, 2003
Posts: 48
String s=new String("Bicycle");
int iBegin=1;
char iEnd=3;
System.out.println(s.substring(iBegin,iEnd));
1) Bic
2) ic
3) icy
4) error: no method matching substring(int,char)
The answer is (4). Does the char value always get converted to int, even in the case of substring function?
Gian Franco
blacksmith
Ranch Hand

Joined: Dec 16, 2003
Posts: 977
Hello Geeta,
I think the answer 4 is wrong. If you run the
code you will see that it produces answer 2: ic
Gian Franco


"Eppur si muove!"
Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522
Hi geeta, the answer is 2 and not 4 as you pointed out. The 'char' datatype is implicitly casted to 'int' since 16-bit fits perfectly in 32-bit.
The signatures for the substring method are:
1) substring (int beginIndex)
2) substring (int beginIndex, int endIndex)
Hope this helps.


- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. <br />- What truth? <br />- That there is no spoon!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question from Marcus Green's exam