|
SCJP question 2
|
|
10-22-2008, 12:13 AM
Post: #1
|
|||
|
|||
|
SCJP question 2
Given:
public class Test{ public enum Dogs{collie,harrier,shepherd}; public static void main(String [] args){ Dogs myDog=Dogs.shepherd; switch(myDog) { case collie: System.out.print("collie"); case default: System.out.print("retreiver"); case harrier: System.out.print("harrier"); } } } what would be the output of this program? Would it print retreiver harrier or would it give a compilation error? |
|||
|
10-22-2008, 02:12 AM
Post: #2
|
|||
|
|||
|
RE: SCJP question 2
Your code is not compiling in my machine. To compile the file I changed case default to just default . So now the code will be
[java] switch(myDog) { case collie: System.out.print("collie"); default: System.out.print("retreiver"); case harrier: System.out.print("harrier"); } [/java] And the above code will print retreiver harrier |
|||
|
« Next Oldest | Next Newest »
|
| Possibly Related Threads... | |||||
| Thread: | Author | Replies: | Views: | Last Post | |
| SCJP practice question | priyaguptan | 6 | 470 |
10-22-2008 01:45 AM Last Post: albinjoseph |
|

Search
Member List
Calendar
Help




