Syvum Home Page

Home > Quiz Games > Java Programming >

Java Programming : Compilation and Execution: Multiple Choice


Answer the following questions about Java syntax and mistakes which can cause compilation errors, as well as the output generated by sample programs.

Formats Info Page Worksheet / Test Paper Quiz Review
Multiple choice

Your Performance  

1.

Which lines of the following will produce an error?
1. byte a1 = 2, a2 = 4, a3;
2. short s = 16;
3. a2 = s;
4. a3 = a1 * a2;
(The lines are numbered only for illustration in this question.)

  Line 3 only

  Line 3 and Line 4

  Line 1 and Line 4

  Line 1 only

  Line 4 only

  Half-n-half Clue
 

2.

The control expression in an "if" statement must be:

  an expression with type boolean

  an expression with either the type boolean or integer

  an expression with either the type boolean or integer with value 0 or 1

  an expression with type integer

  Half-n-half Clue
 

3.

With javadoc, which of the following denotes a javadoc comment?

  //#

  //**

  /**

  /*

  Half-n-half Clue
 

4.

To print the value of a variable "x" of type int, which of the following expressions can be used:
(A) System.out.println("x = " + x);
(B) System.out.println("x = " + String.valueOf(x));
(C) System.out.println("x = " + Integer.toString(x));
(D) System.out.println("x = " + (new Integer(x)).toString());

  (C) and (D)

  (A), (B), (C) and (D)

  (B), (C) and (D)

  (B) and (D)

  Half-n-half Clue
 

5.

Consider the following code:
int i = 1;
switch(c)

  output will be One, followed by Two, and then followed by Three

  code is illegal and therefore will not compile

  output will be One followed by Two

  output will be One

  Half-n-half Clue
 

6.

Are there any errors in the following class definition?
abstract class Class1

  Class header definition is wrong

  Method definition is wrong

  Constructor needs to be defined

  No errors

  Half-n-half Clue
 

7.

Which error does the following code contain: class Class1

  Class Class1 has not been declared public

  Class1 should be declared as abstract

  Method func1() must be declared as static

  There is no error

  Half-n-half Clue
 


 
12 more pages in Java Programming


Contact Info © 1999-2018 Syvum Technologies Inc. Privacy Policy Disclaimer and Copyright
Previous
-
Next
-