Given:
10. class Nav{
11. public enum Direction { NORTH, SOUTH, EAST, WEST }
12. }
13. public class Sprite{
14. //insert code here
15. }
Which code, inserted at line 14, allows the Sprite class to compile?
A. Direction d = NORTH;
B. Nav.Direction d = NORTH;
C. Direction d = Direction.NORTH;
D. Nav.Direction d = Nav.Direction.NORTH;
答案:D
參考:8-5 內部類別、8-6 Java列舉類型
-------------------------------------------------------------------
在14行插入一行程式碼讓程式編譯成功
10. class Nav{
11. public enum Direction { NORTH, SOUTH, EAST, WEST }
12. } //列舉類型在Nav中所以為內部類別,所以在存取上要用外部類別的名稱
沒有留言:
張貼留言