Java 2

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Saifullah
S
Saifullah
Community Contributor
Quizzes Created: 3 | Total Attempts: 2,023
Questions: 42 | Attempts: 1,050

SettingsSettingsSettings
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 x?

    • A.

      2

    • B.

      3

    • C.

      5

    • D.

      6

    Correct Answer
    D. 6
    Explanation
    REF: 93

    Rate this question:

  • 2. 

                      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

    Correct Answer
    B. 3
    Explanation
    REF: 93

    Rate this question:

  • 3. 

    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 **

    Correct Answer
    C. /* Enter Comments Here*/
    Explanation
    REF: 91

    Rate this question:

  • 4. 

    The declaration int a, b, c; is equivalent to which of the following?

    • A.

      Int a b, c;

    • B.

      Int a, b, c;

    • C.

      Int abc;

    • D.

      Int a b c;

    Correct Answer
    B. Int a, b, c;
    Explanation
    REF: 91 | 92

    Rate this question:

  • 5. 

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

    • A.

      Variables

    • B.

      Prompt lines

    • C.

      Named constants

    • D.

      Expressions

    Correct Answer
    B. Prompt lines
    Explanation
    REF: 90

    Rate this question:

  • 6. 

    Which of the following is the newline character?

    • A.

      \r

    • B.

      \n

    • C.

      \l

    • D.

      \b

    Correct Answer
    B. \n
    Explanation
    REF: 80

    Rate this question:

  • 7. 

                      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

    Correct Answer
    A. Insertion Point 1
    Explanation
    REF: 82 | 83

    Rate this question:

  • 8. 

                      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

    Correct Answer
    C. Welcome (on first line) Home (on second line)
    Explanation
    REF: 76

    Rate this question:

  • 9. 

                      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

    Correct Answer
    B. Sum of 5 and 6 = 56
    Explanation
    REF: 72 | 75

    Rate this question:

  • 10. 

                      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 x and y = 11

    • C.

      Sum of x and y = x + y

    • D.

      None of these

    Correct Answer
    A. Sum of 5 and 6 = 11
    Explanation
    REF: 72 | 75

    Rate this question:

  • 11. 

                       Consider the following sequence of statements.   String str; int num1, num2; num1 = 13; num2 = 24; str = "The sum = " + num1 + num2;   What is the final value stored in str?

    • A.

      The sum = 37

    • B.

      The sum = 13 24

    • C.

      The sum = 13 + 24

    • D.

      The sum = 1324

    Correct Answer
    D. The sum = 1324
    Explanation
    REF: 72

    Rate this question:

  • 12. 

    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

    Correct Answer
    A. Beta = beta + 1; alpha = beta;
    Explanation
    REF: 70 | 71

    Rate this question:

  • 13. 

    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

    Correct Answer
    C. Alpha = beta; beta = beta + 1;
    Explanation
    REF: 70 | 71

    Rate this question:

  • 14. 

                       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

    Correct Answer
    A. Only (i) is valid
    Explanation
    REF: 54

    Rate this question:

  • 15. 

                       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.

    Correct Answer
    B. Its value can be changed during program execution.
    Explanation
    REF: 52

    Rate this question:

  • 16. 

    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

    Correct Answer
    D. Both an input statement and an assignment statement
    Explanation
    REF: 54

    Rate this question:

  • 17. 

    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

    Correct Answer
    C. 30
    Explanation
    REF: 54

    Rate this question:

  • 18. 

    The length of the string "computer science" is:

    • A.

      14

    • B.

      15

    • C.

      16

    • D.

      18

    Correct Answer
    C. 16
    Explanation
    REF: 51

    Rate this question:

  • 19. 

    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

    Correct Answer
    C. 19.0
    Explanation
    REF: 49 | 50

    Rate this question:

  • 20. 

    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

    Correct Answer
    A. 20
    Explanation
    REF: 49 | 50

    Rate this question:

  • 21. 

    The expression (int)9.9 evaluates to ____.

    • A.

      9

    • B.

      9.0

    • C.

      9.9

    • D.

      10

    Correct Answer
    A. 9
    Explanation
    REF: 49 | 50

    Rate this question:

  • 22. 

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

    • A.

      7

    • B.

      8

    • C.

      8.0

    • D.

      10

    Correct Answer
    C. 8.0
    Explanation
    REF: 49 | 50

    Rate this question:

  • 23. 

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

    • A.

      13

    • B.

      14

    • C.

      14.8

    • D.

      15

    Correct Answer
    A. 13
    Explanation
    REF: 49 | 50

    Rate this question:

  • 24. 

                       Operators that have two operands are called ____.

    • A.

      Unary operands

    • B.

      Binary operands

    • C.

      Operators

    • D.

      Expressions

    Correct Answer
    B. Binary operands
    Explanation
    REF: 45

    Rate this question:

  • 25. 

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

    • A.

      0

    • B.

      2

    • C.

      3

    • D.

      4

    Correct Answer
    C. 3
    Explanation
    REF: 45

    Rate this question:

  • 26. 

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

    • A.

      0

    • B.

      1

    • C.

      24

    • D.

      25

    Correct Answer
    D. 25
    Explanation
    REF: 41

    Rate this question:

  • 27. 

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

    • A.

      10

    • B.

      14

    • C.

      29

    • D.

      31

    Correct Answer
    D. 31
    Explanation
    REF: 45

    Rate this question:

  • 28. 

                      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

    Correct Answer
    B. X * (y + z)
    Explanation
    REF: 40

    Rate this question:

  • 29. 

                      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

    Correct Answer
    C. X * (y - z) / w
    Explanation
    REF: 40

    Rate this question:

  • 30. 

    The value of the expression 36 – 15 % 2.0 + 1 is ____.

    • A.

      36

    • B.

      36.0

    • C.

      37

    • D.

      This is an illegal Java expression

    Correct Answer
    B. 36.0
    Explanation
    REF: 46 | 47

    Rate this question:

  • 31. 

    The value of 3 % 9 is ___.

    • A.

      0

    • B.

      1/3

    • C.

      3

    • D.

      9

    Correct Answer
    C. 3
    Explanation
    REF: 40

    Rate this question:

  • 32. 

    The value of the expression 17 % 7 is ____.

    • A.

      1

    • B.

      2

    • C.

      3

    • D.

      None of these

    Correct Answer
    C. 3
    Explanation
    REF: 40

    Rate this question:

  • 33. 

    The ____ rules of a programming language tell you which statements are legal, or accepted by the programming language.

    • A.

      Semantic

    • B.

      Logical

    • C.

      Syntax

    • D.

      Grammatical

    Correct Answer
    C. Syntax
    Explanation
    REF: 33

    Rate this question:

  • 34. 

    Which of the following is NOT a special symbol in Java?

    • A.

      +

    • B.

      #

    • C.

      !=

    • D.

      ?

    Correct Answer
    B. #
    Explanation
    REF: 33

    Rate this question:

  • 35. 

    Which of the following is a reserved word in Java?

    • A.

      Char

    • B.

      Char

    • C.

      CHAR

    • D.

      None of these

    Correct Answer
    A. Char
    Explanation
    REF: 34

    Rate this question:

  • 36. 

    Which of the following is NOT a reserved word in Java?

    • A.

      Int

    • B.

      Public

    • C.

      Static

    • D.

      Num

    Correct Answer
    D. Num
    Explanation
    REF: 34

    Rate this question:

  • 37. 

    Which of the following is a valid Java identifier?

    • A.

      1Stop_and_go

    • B.

      #salaryForTheMonth

    • C.

      _Hello_There

    • D.

      MyNumber!

    Correct Answer
    C. _Hello_There
    Explanation
    REF: 34

    Rate this question:

  • 38. 

                     Which of the following is a legal identifier?

    • A.

      Program!

    • B.

      Program_1

    • C.

      1program

    • D.

      Program 1

    Correct Answer
    B. Program_1
    Explanation
    REF: 34

    Rate this question:

  • 39. 

    All of the following are examples of integral data types EXCEPT ____.

    • A.

      Int

    • B.

      Char

    • C.

      Double

    • D.

      Byte

    Correct Answer
    C. Double
    Explanation
    REF: 36

    Rate this question:

  • 40. 

    Which of the following is a valid int value?

    • A.

      46,259

    • B.

      46259

    • C.

      462.59

    • D.

      None of these

    Correct Answer
    B. 46259
    Explanation
    REF: 37

    Rate this question:

  • 41. 

    What is the floating-point notation for 25.611?

    • A.

      2.5E1

    • B.

      2.6

    • C.

      2.561100E1

    • D.

      256.1100E1

    Correct Answer
    C. 2.561100E1
    Explanation
    REF: 39

    Rate this question:

  • 42. 

    The value of the expression 44 / 10 is _____.

    • A.

      0.4

    • B.

      4

    • C.

      4.0

    • D.

      4.4

    Correct Answer
    B. 4
    Explanation
    REF: 40

    Rate this question:

Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.