Followers

Sunday, 5 August 2012

Java keywords


Question31

class GRC4 {public static void main(String[] args) {}} // 1
class GRC5 {public static void main(String []args) {}} // 2
class GRC6 {public static void main(String args[]) {}} // 3
What is the result of attempting to compile and run the above programs?
a.   Compile-time error at line 1.
b.  Compile-time error at line 2.
c.   Compile-time error at line 3.
d.  An attempt to run GRC4 from the command line fails.
e.   An attempt to run GRC5 from the command line fails.
f.   An attempt to run GRC6 from the command line fails.
g.  None of the above

Question 32

class GRC7 {public void main(String[] args) {}} // 1
class GRC8 {public void main(String []args) {}} // 2
class GRC9 {public void main(String args[]) {}} // 3
What is the result of attempting to compile and run the above programs?
a.   Compile-time error at line 1.
b.  Compile-time error at line 2.
c.   Compile-time error at line 3.
d.  An attempt to run GRC7 from the command line fails.
e.   An attempt to run GRC8 from the command line fails.
f.   An attempt to run GRC9 from the command line fails.

Question 33

class GRC1 {public static void main(String[] args) {}}    // 1
class GRC2 {protected static void main(String[] args) {}} // 2
class GRC3 {private static void main(String[] args) {}}   // 3
What is the result of attempting to compile each of the three class declarations and invoke each main method from the command line?
a.   Compile-time error at line 1.
b.  Compile-time error at line 2.
c.   Compile-time error at line 3.
d.  An attempt to run GRC1 from the command line fails.
e.   An attempt to run GRC2 from the command line fails.
f.   An attempt to run GRC3 from the command line fails.


Question 34

Which of these words belongs to the set of Java keywords?
a.   Qualified
b.  record
c.   repeat
d.  restricted
e.   label
f.   to
g.  type
h.  until
i.   value
j.   virtual
k.  xor
l.   None of the above

Question 35

Which of these words belong to the set of Java keywords?
a.   exit
b.  strictfp
c.   enum
d.  super
e.   abort
f.   event
g.  goto
h.  native
i.   exception

Question 36

Which of these words belong to the set of Java keywords?
a.   Double
b.  goto
c.   min
d.  extern
e.   new
f.   signed
g.  finally
h.  const
i.   and
j.   array
k.  do

Question37

Which of these words belong to the set of Java keywords?
a.   declare
b.  global
c.   const
d.  preserve
e.   continue
f.   Float
g.  extends
h.  select
i.   break
j.   dim
k.  instanceOf

Question 38

Which of these words belong to the set of Java keywords?
a.   next
b.  catch
c.   function
d.  instanceof
e.   mod
f.   const
g.  or
h.  Boolean
i.   goto
j.   import
k.  transient

Question 39

Which of these words belong to the set of Java keywords?
a.    byte
b.   short
c.    int
d.   long
e.    decimal
f.    int64
g.   float
h.   single
i.    double
j.    boolean
k.   char
l.    unsigned
m.  array
n.   string

Question 40

Which of these words belongs to the set of Java keywords?
a.   clause
b.  loop
c.   expression
d.  overrides
e.   statement
f.   assertion
g.  validate
h.  exception
i.   cast
j.   None of the above

Question 41

Which of these words belong to the set of Java keywords?
a.   transient
b.  serializable
c.   runnable
d.  run
e.   volatile
f.   externalizable
g.  cloneable

Question 42

Which of these words belong to the set of Java keywords?
a.   virtual
b.  goto
c.   ifdef
d.  typedef
e.   friend
f.   struct
g.  implements
h.  union
i.   const

Question 43

Which of these lists contains at least one word that is not a Java keyword?
a.   abstract, default, if, private, this
b.  do, implements, protected, boolean, throw
c.   case, extends, int, short, try
d.  import, break, double, exception, throws
e.   byte, else, instanceof, return, transient
f.   None of the above

Question 44

Which of these lists contains at least one word that is not a Java keyword?
a.   interface, static, void, catch, final
b.  char, strictfp, finally, long, volatile
c.   native, super, class, float, while
d.  const, for, new, switch, import
e.   continue, finalize, goto, package, synchronized
f.   None of the above


Question 45

class GFM11{
  public static void main (String[] args) {
    int x,y,z;
    System.out.println(x+y+z);
}}
What is the result of attempting to compile and run the program?
a.   Prints nothing.
b.  Prints an undefined value.
c.   Prints: null
d.  Prints: 0
e.   Run-time error
f.   Compile-time error
g.  None of the above

Answers



31
None of the above 
Section 12.1.4 of the Java Language Specification requires that the main method must accept a single argument that is an array of components of type String. In each of the three class declarations, the single argument is indeed an array of components of type String. Please note that the square brackets within an array declaration may appear as part of the type or part of the declarator (i.e. array name).  
32
d  e  f 
An attempt to run GRC7 from the command line fails.  An attempt to run GRC8 from the command line fails.  An attempt to run GRC9 from the command line fails. 
Section 12.1.4 of the JLS requires the main method to be declared static. In this example, each of the three main methods are not declared static. The result is an error at run-time.  
33
e  f 
An attempt to run GRC2 from the command line fails.  An attempt to run GRC3 from the command line fails. 
Section 12.1.4 of the JLS requires the main method to be declared public. The main methods of GRC2 and GRC3 are not declared public and can not be invoked from the command line using a JVM that is compliant with section 12.1.4. Not every JVM enforces the rule. Even so, for the purposes of the SCJP exam, the main method should be declared as required by the JLS.  
34
None of the above 
All of these are keywords of the Pascal programming language, but none are Java keywords.  
35
b  d  g  h 
strictfp  super  goto  native 
 
36
b  e  g  h  k 
goto  new  finally  const  do 
 
37
c  e  g  i 
const  continue  extends  break 
All of the letters of all Java keywords are lower case. The word instanceof is a Java keyword, but instanceOf is not.  
38
b  d  f  i  j  k 
catch  instanceof  const  goto  import  transient 
 
39
a  b  c  d  g  i  j  k 
byte  short  int  long  float  double  boolean  char 
 
40
None of the above 
 
41
a  e 
transient  volatile 
Serializable, Runnable, Externalizable, and Cloneable are all interfaces. Thread.run is a method. The keywords transient and volatile are field modifiers.  
42
b  g  i 
goto  implements  const 
The words virtual, ifdef, typedef, friend, struct and union are all words related to the C programming language. Although the words const and goto are also related to the C programming language, they are also Java keywords.  
43
import, break, double, exception, throws 
The word exception is not a Java keyword. The words import, break, double and throws are Java keywords.  
44
continue, finalize, goto, package, synchronized 
The word finalize is the name of a method of the Object class: It is not a keyword. The words continue, goto, package and synchronized are all Java keywords.  
45
Compile-time error 
Variables declared inside of a block or method are called local variables; they are not automatically initialized. The compiler will generate an error as a result of the attempt to access the local variables before a value has been assigned.  

No comments:

Post a Comment