About Question enthuware.ocajp.i.v7.2.860 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
ETS User

About Question enthuware.ocajp.i.v7.2.860 :

Post by ETS User »

public void switchString(String input){
switch(input){
case "a" : System.out.println( "apple" );
case "b" : System.out.println( "bat" );
break;
case "B" : System.out.println( "big bat" );
default : System.out.println( "none" );
}
}

public static void main(String[] args) throws Exception {
TestClasstc = new TestClass();
tc.switchString("B");
}

hi according to eclipse switch cannot evaluate string so this won't compile....

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.860 :

Post by admin »

Please try using JDK 1.7.

HTH,
Paul.

jeff_kola
Posts: 3
Joined: Mon Dec 07, 2020 1:34 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.860 :

Post by jeff_kola »

I thought the switch variable needs to be a compile time constant, and not passed through as parameters to functions according to Selikoff and Boyarsky book.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.860 :

Post by admin »

No, switch case labels must be constants, not the switch variable.

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests