Home
›
MCQs
›
Java Programming
›
Module 5: Object-Oriented Programming — Classes & Objects - Final Quiz
PRACTICE • LEARN • GROW
Module 5: Object-Oriented Programming — Classes & Objects - Final Quiz MCQs
Solve topic-wise placement questions and improve your skills.
Module 5: Object-Oriented Programming — Classes & Objects - 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 fundamental difference between a Class and an Object in Java?
A.
A Class is allocated on the heap while an Object is allocated in the CPU register
B.
A Class is a blueprint defining structure and behavior; an Object is a concrete instance allocated in heap memory
C.
An Object can exist without a Class definition
D.
A Class can only hold primitive variables
Explanation & Key
Correct Answer:
2
What is the return type of a Java constructor?
A.
void
B.
Object
C.
Constructors do NOT have a return type, not even void
D.
int
Explanation & Key
Correct Answer:
3
What rule governs the use of
this() for constructor chaining inside a constructor?
A.
this() can be placed anywhere inside the constructor body
B.
this() must strictly be the first statement in the constructor body
C.
this() can be called multiple times in the same constructor
D.
this() is only permitted in static methods
Explanation & Key
Correct Answer:
4
What happens when compiling the following class containing a static method?
class Account {
int balance = 1000;
static void display() {
System.out.println(balance);
}
}
A.
Compiles and prints 1000
B.
Compile-time error: non-static variable balance cannot be referenced from a static context
C.
Compiles and prints 0
D.
Throws NullPointerException at runtime
Explanation & Key
Correct Answer:
5
What will be the output order when executing this class with static and instance blocks?
class Demo {
static { System.out.print("S "); }
{ System.out.print("I "); }
Demo() { System.out.print("C "); }
public static void main(String[] args) {
new Demo();
new Demo();
}
}
A.
S I C I C
B.
S C I S C I
C.
I C S I C
D.
C I S C I
Explanation & Key
Correct Answer:
6
Which change does NOT constitute a valid method overload in Java?
A.
Changing the number of parameters
B.
Changing the data types of parameters
C.
Changing only the method return type without changing parameter types
D.
Changing the sequence of parameter types
Explanation & Key
Correct Answer:
7
When does the Java compiler automatically generate a default no-argument constructor for a class?
A.
For every class always
B.
Only when the class defines NO constructors at all
C.
Whenever all fields are public
D.
Only when implementing Serializable
Explanation & Key
Correct Answer:
8
What will be printed when instantiating new Beta("test")?
class Alpha {
Alpha() { System.out.print("A "); }
}
class Beta extends Alpha {
Beta() {
super();
System.out.print("B ");
}
Beta(String s) {
this();
System.out.print("C ");
}
}
// main: new Beta("test");
A.
C B A
B.
A B C
C.
B A C
D.
A C
Explanation & Key
Correct Answer:
9
What will be printed by the following code testing static vs instance variables?
class Counter {
static int count = 0;
int instanceCount = 0;
Counter() {
count++;
instanceCount++;
}
}
Counter c1 = new Counter();
Counter c2 = new Counter();
Counter c3 = new Counter();
System.out.println(Counter.count + " " + c3.instanceCount);
A.
1 1
B.
3 1
C.
3 3
D.
1 3
Explanation & Key
Correct Answer:
10
What happens when executing the following method overload call?
class OverloadTest {
static void test(int a, double b) { System.out.print("int-double"); }
static void test(double a, int b) { System.out.print("double-int"); }
public static void main(String[] args) {
// test(10, 20); // What happens here?
}
}
A.
Prints 'int-double'
B.
Prints 'double-int'
C.
Compile-time error: reference to test is ambiguous
D.
Runtime Exception
Explanation & Key
Correct Answer:
11
Why is the
finalize() method in java.lang.Object deprecated and removed in modern Java?
A.
Because it consumed too much disk space
B.
Because its execution by the garbage collector was non-deterministic, error-prone, and prone to severe performance bottlenecks and resource leaks
C.
Because modern computers do not require garbage collection
D.
Because it could only be invoked in single-threaded programs
Explanation & Key
Correct Answer:
Question Palette
Answered
Current
Not Attempted
Wrong