Java 2

42 Questions | Total Attempts: 286

SettingsSettingsSettings
Please wait...
Java Quizzes & Trivia

Basic Elements of Java


Questions and Answers
  • 1. 
                      Suppose x = 2 and y = 3.  If the statement   x *= y;   is executed once, what is the value of y?
    • A. 

      2

    • B. 

      3

    • C. 

      5

    • D. 

      6

  • 2. 
    Which of the following is the correct syntax for commenting in Java?
    • A. 

      # Enter Comments Here

    • B. 

      ""

    • C. 

      /* Enter Comments Here*/

    • D. 

      ** Enter Comments Here **

  • 3. 
    ____ are executable statements that inform the user what to do.
    • A. 

      Variables

    • B. 

      Prompt lines

    • C. 

      Named constants

    • D. 

      Expressions

  • 4. 
    Which of the following is the newline character?
    • A. 

      \r

    • B. 

      \n

    • C. 

      \l

    • D. 

      \b

  • 5. 
                      Consider the following program.   // Insertion Point 1 public class CircleArea {       // Insertion Point 2     static final float PI = 3.14       public static void main(String[]args)     {        //Insertion Point 3          float r = 2.0;        float area;        area = PI * r * r;        System.out.println("Area = " + area);     }      // Insertion Point 4 }   In the above code, where do the import statements belong?
    • A. 

      Insertion Point 1

    • B. 

      Insertion Point 2

    • C. 

      Insertion Point 3

    • D. 

      Insertion Point 4

  • 6. 
                      What is the output of the following statement?   System.out.println("Welcome \n Home");
    • A. 

      WelcomeHome

    • B. 

      Welcome Home

    • C. 

      Welcome (on first line) Home (on second line)

    • D. 

      Welcome \n Home

  • 7. 
                      Suppose that x = 5 and y = 6. What is the output of the following Java statement?   System.out.println("Sum of " + x + " and " + y + " = "   + x + y);          
    • A. 

      Sum of 5 and 6 = 11

    • B. 

      Sum of 5 and 6 = 56

    • C. 

      Sum of x and y = 11

    • D. 

      None of these

  • 8. 
    Suppose that alpha and beta are int variables. The statement alpha = ++beta; is equivalent to the statement(s) ____.
    • A. 

      Beta = beta + 1; alpha = beta;

    • B. 

      Alpha = 1 + beta;

    • C. 

      Alpha = alpha + beta;

    • D. 

      None of these

  • 9. 
    Suppose that alpha and beta are int variables. The statement alpha = beta++; is equivalent to the statement(s) ____.
    • A. 

      Alpha = 1 + beta;

    • B. 

      Alpha = alpha + beta;

    • C. 

      Alpha = beta; beta = beta + 1;

    • D. 

      None of these

  • 10. 
                       Given   int      one; double   two; boolean  four;   Which of the following assignment statements are valid? (i)   one = 7 + 3 % 4; (ii)  2.3 + 3.5 = two; (iii) four = (2 <= 3);
    • A. 

      Only (i) is valid

    • B. 

      (i) and (ii) are valid

    • C. 

      (ii) and (iii) are valid

    • D. 

      (i) and (iii) are valid

  • 11. 
                       Which of the following statements about a named constant is NOT true?
    • A. 

      Its content cannot change during program execution.

    • B. 

      Its value can be changed during program execution.

    • C. 

      It is a memory location.

    • D. 

      It is declared using the reserved word final.

  • 12. 
    What type of Java statement(s) stores a value in a variable?
    • A. 

      Input

    • B. 

      Output

    • C. 

      Assignment

    • D. 

      Both an input statement and an assignment statement

  • 13. 
    Suppose that x and y are int variables and x = 10 and y = 20. After the statement: x = x + y; executes, the value of x is ____.
    • A. 

      10

    • B. 

      20

    • C. 

      30

    • D. 

      None of these

  • 14. 
    The length of the string "computer science" is:
    • A. 

      14

    • B. 

      15

    • C. 

      16

    • D. 

      18

  • 15. 
    Suppose that alpha is a double variable. What is the value of alpha after the following statement executes: alpha = 11.5 + (double)(15) / 2;
    • A. 

      18.0

    • B. 

      18.5

    • C. 

      19.0

    • D. 

      None of these

  • 16. 
    Suppose that x is an int variable. What is the value of x after the following statement executes: x = 15 + (int)(10.5) / 2;.
    • A. 

      20

    • B. 

      20.25

    • C. 

      21

    • D. 

      22

  • 17. 
    The expression (int)9.9 evaluates to ____.
    • A. 

      9

    • B. 

      9.0

    • C. 

      9.9

    • D. 

      10

  • 18. 
    The expression (double)(6 + 2) evaluates to ____.
    • A. 

      7

    • B. 

      8

    • C. 

      8.0

    • D. 

      10

  • 19. 
    The expression (int)6.9 + (int)7.9 evaluates to ____.
    • A. 

      13

    • B. 

      14

    • C. 

      14.8

    • D. 

      15

  • 20. 
                       Operators that have two operands are called ____.
    • A. 

      Unary operands

    • B. 

      Binary operands

    • C. 

      Operators

    • D. 

      Expressions

  • 21. 
    The value of the expression 1 + 5 % 3 is ____.
    • A. 

      0

    • B. 

      2

    • C. 

      3

    • D. 

      4

  • 22. 
    The value of the expression 26 – 14 % 3 + 1 is ____.
    • A. 

      0

    • B. 

      1

    • C. 

      24

    • D. 

      25

  • 23. 
    The value of the expression 26 + 14 / 3 + 1 is ____.
    • A. 

      10

    • B. 

      14

    • C. 

      29

    • D. 

      31

  • 24. 
                      Suppose that x, y and z are int variables. The expression x(y+z) in Java is written as ____.
    • A. 

      X * y + z

    • B. 

      X * (y + z)

    • C. 

      Y + x * z

    • D. 

      None of these

  • 25. 
                      Suppose that x, y, z, and w are int variables. The expression x(y-z)/w in Java is written as ____.
    • A. 

      X * y - z / w

    • B. 

      X * y - x * z / w

    • C. 

      X * (y - z) / w

    • D. 

      X (y - z) / w

Back to Top Back to top