Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

One of the Mock Questions Cannot be Compiled

 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3760
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
umang bhartia
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic