SCJP 1.6版考題 112
出自 陳富國維基館
Given: 12. public class Test{ 13. public enum Dogs{collie, harrier); 14. public static void main(String[] args){ 15. Dogs myDog = Dogs.collie; 16. switch(myDog){ 17. case collie: 18. System.out.print("collie "); 19. case harrier: 20. System.out.print("harrier "); 21. } 22. } 23. } What is the result? A. collie B. harrier C. Compilation fails. D. collie harrier E. An exception is thrown at runtime.
解答
Ans: D
解說: myDog = Dogs.collie,所以會進入case collie執行,只是此case沒有設break,後面的case會跟著執行
|