1.
Which of the following is NOT a reserved word in Java?
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.
2.
Which of the following integer primitive types can correctly represent a value of 65000?
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.
3.
Which of the following statements declaring and initializing boolean primitive variables would not be rejected by the Java compiler?
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.
4.
Which of the following variable names will be rejected by the Java compiler?
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.
5.
Which of the following is the range of values that a byte can store?
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.
6.
Which of the following uses the same number of bits as the int primitive variable?
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.
7.
How many bits does a Java double primitive value use?
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.
8.
-
lightspeed = 1816000;
-
days = 1000;
-
seconds = days * 24 * 60 * 60;
-
distance = lightspeed * seconds;
When this block of code is executed, what will be the value of variable seconds after the execution of line 3 ?
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.
9.
-
int answer;
-
answer = 50;
-
answer = answer+1;
What will be the value assigned to variable answer after executing this code?
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.
10.
-
byte b = 50;
-
b = b * 2;
What will happen if you try to compile this block of code?
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.