aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes using switch case? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "using switch case?" Watch "using switch case?" New topic
Author

using switch case?

maggie joseph
Ranch Hand

Joined: Dec 29, 2009
Posts: 185

compile time error???
answer is
constant expressions needed???x and y are not constants...
what does this mean??
saima kanwal
Ranch Hand

Joined: Oct 05, 2009
Posts: 148
the problem is with variable y: it should be a constant (that is should be marked final) and it should be a compile time constant which means that y should be declared and initialized at the same time.Refer to page 336 Chapter 5 of K & B .

so the correct code is :



SCJP 6.0 (86%) SCWCD 5 (94%)
Ankit Garg
Saloon Keeper

Joined: Aug 03, 2008
Posts: 9189
    
    2

maggie you are not following the quoting of source rule properly. You've asked a lot of questions without a proper source (like this, this, this and this). Quoting source is not optional at javaranch. If you don't quote the source properly, then we might have to delete your questions...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
maggie joseph
Ranch Hand

Joined: Dec 29, 2009
Posts: 185
ok..i will do that from next post..actually i am trying lots of code on my own too.so its a combination of all that..anyways i will take care from next time....
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12907
    
    3

maggie joseph wrote:ok..i will do that from next post..

No. Tell us what the source of the above question is now. As you've been told multiple times, it's required on JavaRanch.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

The case constant must be a compile time constant! Since the case argument has to be resolved at compile time, that means you can use only a constant or final variable that is assigned to literal value.

I think, this may help to you.!


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Alpesh Rathod
Ranch Hand

Joined: Jan 06, 2009
Posts: 41
Abimaran Kugathasan wrote:The case constant must be a compile time constant! Since the case argument has to be resolved at compile time, that means you can use only a constant or final variable that is assigned to literal value.

I think, this may help to you.!



Very good very good...


Thanks,
Alps
maggie joseph
Ranch Hand

Joined: Dec 29, 2009
Posts: 185
question is from Examlab most probably.....
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: using switch case?
 
Similar Threads
Inner class question from Dan's exam
Confused about Dan's exam...
switch case basic
changing a final variable
A Programming Interview Question