PRACTICE • LEARN • GROW
Module 2: Variables & Data Types - Final Quiz MCQs
Solve topic-wise placement questions and improve your skills.
Module 2: Variables & Data Types - Final Quiz Progress
0 of 11 completed
0%
Topic Track
You are viewing MCQs in preview mode. Log in to select options, submit answers, and track your progress.
Log In to Answer
1
What is the bit-width and byte size of a
long primitive variable in Java across all operating systems?
A.
32 bits (4 bytes)
B.
64 bits (8 bytes)
C.
128 bits (16 bytes)
D.
Platform-dependent (32 bits on 32-bit OS, 64 bits on 64-bit OS)
Explanation & Key
Correct Answer:
2
Where are local primitive variables and actual object instances stored in Java's runtime memory?
A.
Local primitives are in the Stack; actual object instances reside in the Heap
B.
Both local primitives and objects reside exclusively in the Stack
C.
Both local primitives and objects reside exclusively in the Heap
D.
Primitives are in the CPU cache; objects reside in disk swap space
Explanation & Key
Correct Answer:
3
What will be the value of result after executing this narrowing cast?
double score = 3.89;
int result = (int) score;
System.out.println(result);
A.
4 (rounded up)
B.
3 (fraction truncated)
C.
3.89
D.
Compilation error
Explanation & Key
Correct Answer:
4
What will be the output of the following code snippet comparing String objects?
String s1 = new String("ReadyToGo");
String s2 = new String("ReadyToGo");
System.out.println((s1 == s2) + " " + s1.equals(s2));
A.
true true
B.
false true
C.
true false
D.
false false
Explanation & Key
Correct Answer:
5
What is the effect of applying the
final keyword to a variable declaration in Java?
A.
The variable can only be accessed by the final line of the program
B.
The variable becomes a constant whose value cannot be reassigned once initialized
C.
The variable is deleted immediately after the method exits
D.
The variable can hold any data type dynamically
Explanation & Key
Correct Answer:
6
What is the output of the following integer division and modulus code?
int a = 17;
int b = 4;
System.out.println((a / b) + " " + (a % b));
A.
4.25 1
B.
4 1
C.
4 4
D.
4.0 1.0
Explanation & Key
Correct Answer:
7
What will be printed by the following ternary and increment snippet?
int x = 5;
int y = (x++ > 5) ? 10 : 20;
System.out.println("x=" + x + ", y=" + y);
A.
x=6, y=10
B.
x=6, y=20
C.
x=5, y=20
D.
x=5, y=10
Explanation & Key
Correct Answer:
8
Which identifier violates Java naming conventions for a class name?
A.
userAccountManager
B.
UserAccountManager
C.
PaymentProcessor
D.
BankClient
Explanation & Key
Correct Answer:
9
What will happen when attempting to compile the following code?
byte a = 10;
byte b = 20;
byte c = a + b;
System.out.println(c);
A.
It compiles and prints 30
B.
Compile-time error: possible lossy conversion from int to byte
C.
Runtime overflow exception
D.
It prints 0
Explanation & Key
Correct Answer:
10
What will be printed by the following compound assignment operator snippet?
short s = 10;
s += 5;
System.out.println(s);
A.
Compile-time error: cannot add int literal to short
B.
15
C.
Runtime ClassCastException
D.
0
Explanation & Key
Correct Answer:
11
What is the output of the following IEEE 754 floating-point comparison?
double d1 = 0.1 + 0.2;
System.out.println(d1 == 0.3);
A.
true
B.
false
C.
Compile-time error
D.
NaN
Explanation & Key
Correct Answer:
Question Palette
Answered
Current
Not Attempted
Wrong