This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes One of the Mock Questions Cannot be Compiled Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "One of the Mock Questions Cannot be Compiled" Watch "One of the Mock Questions Cannot be Compiled" New topic
Author

One of the Mock Questions Cannot be Compiled

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
I got this question form JQPlus:
public class Tester {
static String s1 = sM1("a");
{ s1 = sM1("b"); }
static {
s1 = sM1("C");
}
public static void main( String args[] ) {
Tester it = new Tester();
}
private static String sM1( string s ) {
System.out.println(s);
return s;
}
}
The answer is that 'a','c','b'will be printed in that order. However, I could not compite the program when I tried to test it myself. My attempt to fix the program failed. how should it be fixed?
Paul Caudle
Ranch Hand

Joined: Jun 08, 2000
Posts: 64
Hey there JiaPei,
I got it to work simply by capitalizing the S in string in the method header of sM1(String s).
Let me know if that doesn't work for you.
Paul
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3254
    
    2
Good catch!
In line : private static String sM1( string s ) {
change small case 's' of "string" to "String".
(Could you please tell me the Question Id, so that I can fix it?)
-Paul.
------------------
Get Certified, Guaranteed!
(Now Revised for the new Pattern)
www.enthuware.com/jqplus

[This message has been edited by Paul Anil (edited November 29, 2000).]


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
umang bhartia
Ranch Hand

Joined: Sep 29, 2000
Posts: 60
Hay that was just a typing mistake, as all u need to fix up your probem is change the parameter in your method sM1() to String instead of string. that is all, now u can eaisly run the program
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: One of the Mock Questions Cannot be Compiled
 
Similar Threads
Help with class initialization
Static and Instance Blocks..
Doubt
Initializing Sequence
initialization sequence - what is done first?