Itemp Java Quiz 3

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 Ekkoo
E
Ekkoo
Community Contributor
Quizzes Created: 4 | Total Attempts: 2,553
Questions: 10 | Attempts: 184

SettingsSettingsSettings
Java Quizzes & Trivia

Chapter 3 Revision


Questions and Answers
  • 1. 

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

    • A.

      Import

    • B.

      Finally

    • C.

      Friend

    • D.

      Goto

    Correct Answer
    C. Friend
    Explanation
    In Java, "friend" is not a reserved word. Reserved words are predefined keywords that have special meanings and cannot be used as identifiers (such as variable names or class names) in the program. "import", "finally", and "goto" are all examples of reserved words in Java.

    Rate this question:

  • 2. 

    Which of the following integer primitive types can correctly represent a value of 65000?

    • A.

      Short

    • B.

      Int

    • C.

      Byte

    • D.

      All of these

    Correct Answer
    B. Int
    Explanation
    The int primitive type can correctly represent a value of 65000. Integers are whole numbers without any decimal points, and the int type can store values up to 2,147,483,647. Since 65000 falls within this range, it can be accurately represented using the int data type.

    Rate this question:

  • 3. 

    Which of the following statements declaring and initializing boolean primitive variables would not be rejected by the Java compiler?

    • A.

      Boolean flag = true;

    • B.

      Boolean flag = true;

    • C.

      Boolean flag = TRUE;

    • D.

      Boolean flag = TRUE;

    Correct Answer
    A. Boolean flag = true;
    Explanation
    The correct answer is "boolean flag = true;". In Java, boolean primitive variables can only be assigned the values "true" or "false" in lowercase letters. The other options are incorrect because they either use the wrong case for the boolean values or use the Boolean wrapper class instead of the boolean primitive type.

    Rate this question:

  • 4. 

    Which of the following variable names will be rejected by the Java compiler?

    • A.

      Animal

    • B.

      2ndletter

    • C.

      _me2you

    • D.

      $price

    Correct Answer
    B. 2ndletter
    Explanation
    Variable names in Java cannot start with a number. They must begin with a letter, an underscore, or a dollar sign. Therefore, the variable name "2ndletter" will be rejected by the Java compiler.

    Rate this question:

  • 5. 

    Which of the following is the range of values that a byte can store?

    • A.

      -127 to 127

    • B.

      -127 to 128

    • C.

      -128 to 127

    • D.

      0 to 255

    Correct Answer
    C. -128 to 127
    Explanation
    A byte is a data type in computer programming that can store 8 bits of information. In binary, the leftmost bit is used to represent the sign of the number, with 0 indicating a positive number and 1 indicating a negative number. Therefore, in the range of values that a byte can store, the leftmost bit can be either 0 or 1, resulting in a range of -128 to 127.

    Rate this question:

  • 6. 

    Which of the following uses the same number of bits as the int primitive variable?

    • A.

      Byte

    • B.

      Float

    • C.

      Long

    • D.

      Double

    Correct Answer
    B. Float
    Explanation
    The float data type in Java uses the same number of bits as the int data type, which is 32 bits. Both int and float can store 32 bits of information, although they represent different types of values. Int is used for storing whole numbers, while float is used for storing decimal numbers with a wider range and less precision.

    Rate this question:

  • 7. 

    How many bits does a Java double primitive value use?

    • A.

      32 bits

    • B.

      48 bits

    • C.

      64 bits

    • D.

      128 bits

    Correct Answer
    C. 64 bits
    Explanation
    A Java double primitive value uses 64 bits. A double is a data type in Java that represents a decimal number with double precision. It is stored using 64 bits, which allows for a wide range of values and a high level of precision. This allows for accurate calculations and storage of decimal numbers in Java programs.

    Rate this question:

  • 8. 

    1. lightspeed = 1816000;
    2. days = 1000;
    3. seconds = days * 24 * 60 * 60;
    4. distance = lightspeed * seconds;
    When this block of code is executed, what will be the value of variable seconds after the execution of line 3 ?

    • A.

      1816000

    • B.

      1000

    • C.

      86400000

    • D.

      156200000000

    Correct Answer
    C. 86400000
    Explanation
    The variable "seconds" will have a value of 86400000 after the execution of line 3. This is because the variable "days" is multiplied by 24 (hours in a day), then by 60 (minutes in an hour), and finally by 60 (seconds in a minute), resulting in the total number of seconds in 1000 days.

    Rate this question:

  • 9. 

    1. int answer; 
    2. answer = 50;
    3. answer = answer+1;
    What will be the value assigned to variable answer after executing this code?

    • A.

      0

    • B.

      Null

    • C.

      50

    • D.

      51

    Correct Answer
    D. 51
    Explanation
    The value assigned to the variable answer after executing this code will be 51. This is because the code first assigns the value 50 to the variable answer, and then adds 1 to it using the += operator. This results in answer being incremented by 1, making it equal to 51.

    Rate this question:

  • 10. 

    1. byte b = 50;
    2. b = b * 2; What will happen if you try to compile this block of code?

    • A.

      It will compile successfully

    • B.

      It will give error: Cannot assign an int to a byte!

    • C.

      It will give error because the answer is above the limit of a byte

    • D.

      It will give error because a byte is not suitable for multiplication.

    Correct Answer
    B. It will give error: Cannot assign an int to a byte!
    Explanation
    The code will give an error because the result of the multiplication operation is an int, and it cannot be directly assigned to a byte variable.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 17, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Apr 20, 2011
    Quiz Created by
    Ekkoo
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.