[問題] OCJP SE6題目 - enum
Given:
enum Example {ONE, TWO, THREE}
Which statement is true?
A. The expressions (ONE == ONE) and ONE.equals(ONE) are both guaranteed to be
true.
B. The expression (ONE < TWO) is guaranteed to be true and ONE.compareTo(TWO)
is guaranteed to be less than one.
C. The Example values cannot be used in a raw java.util.HashMap; instead, the
programmer must use a java.util.EnumMap.
d. The Example values can be used in a java.util.SortedSet, but the set will
NOT be sorted because enumerated types do NOT implement java.lang.Comparable
------------------
The answer: A
想請問B,C,D是哪部分錯了, 這題不會得太多,實在沒有辦法做判斷。
A我倒是較能理解,因為ONE其實會是一個繼承Enum的類別,所以ONE==ONE物件記憶體位置
相同; ONE.equals(ONE), 我只知道System.out.println(Example.ONE); 會得到字串
ONE, 所以知道會對。
跟大家請教一下了,謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.200.217.72
※ 文章網址: https://www.ptt.cc/bbs/java/M.1487502125.A.5A5.html
→
02/20 00:28, , 1F
02/20 00:28, 1F
→
02/20 00:37, , 2F
02/20 00:37, 2F
→
02/20 00:37, , 3F
02/20 00:37, 3F
→
02/20 00:39, , 4F
02/20 00:39, 4F
修正錯字 java."util".SortedSet
※ 編輯: uopsdod (180.217.174.122), 02/20/2017 21:03:35
修正錯字 java.util.HashMap
※ 編輯: uopsdod (180.217.174.122), 02/20/2017 21:04:41
→
02/20 21:05, , 5F
02/20 21:05, 5F
→
02/20 21:05, , 6F
02/20 21:05, 6F
修正錯字 enum Example
※ 編輯: uopsdod (180.217.174.122), 02/20/2017 21:06:27
→
02/20 21:14, , 7F
02/20 21:14, 7F
→
02/20 21:14, , 8F
02/20 21:14, 8F
→
02/23 09:36, , 9F
02/23 09:36, 9F
→
02/25 06:38, , 10F
02/25 06:38, 10F
→
03/01 19:11, , 11F
03/01 19:11, 11F
→
03/01 19:15, , 12F
03/01 19:15, 12F
→
03/01 19:15, , 13F
03/01 19:15, 13F
→
03/01 19:15, , 14F
03/01 19:15, 14F
→
03/01 19:15, , 15F
03/01 19:15, 15F
→
03/01 19:15, , 16F
03/01 19:15, 16F
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):
java 近期熱門文章
PTT數位生活區 即時熱門文章