先看一道java笔记题目:
下面中哪些是JAVA中的关键字?
A. transient
B. volatile
C. Int
D. true
E. null
F. false
你的答案是什么?DEF ? ABDEF ?
都错!不会吧?怎么会错呢?其实,我觉得这样的题目很无聊!我们有必要记这些无谓的东西吗?退一步来讲,这些真的很无谓,但是如果你要参加考试或者找工作面试笔试,还是不得不去面对这样的题目。只要平时看书注意一点,这道题还是不难做的。
首先java中的关键字都是首字母小写,排除C,还有一个就是true
,false ,
null在java中不是关键字,也不是保留字,它们只是显式常量值,有sun官方解释为证!
Here's a list of keywords in the Java programming language. You
cannot use any of the following as identifiers in your programs.
The keywords const and goto are reserved, even though they are not
currently used. true, false, and null might seem like keywords, but
they are actually literals; you cannot use them as identifiers in
your programs.
Abstract continue for new
switch
assert*** default goto* package synchronized
boolean do if private this
break double implements protected throw
byte else import public throws
case enum**** instanceof return transient
catch extends int short try
char final interface static void
class finally long strictfp** volatile
const* float native super while
* not used
** added in 1.2
*** added in 1.4
**** added in 5.0
注意红色部分,大意是:true,false,null看起来可能像是关键字,但它们实际上是常量值。你不能把它们用作标识符!现在,你知道这道题的答案了吧?答案就是AB