Java Programming — OOP in Java
Java OOP, collections, multithreading
100 Questions 10 Topics Take Test
Advertisement
Showing 81–90 of 100 questions in OOP in Java
Q.81 Easy OOP in Java
In Java, which keyword is used to create a reference variable that cannot point to a different object after initialization?
A static
B final
C volatile
D synchronized
Correct Answer:  B. final
EXPLANATION

The 'final' keyword when applied to a reference variable makes it immutable, meaning it cannot be reassigned to point to another object.

Take Test
Q.82 Easy OOP in Java
Which of the following access modifiers allows a variable to be accessed only within the same class?
A private
B protected
C public
D default
Correct Answer:  A. private
EXPLANATION

The 'private' access modifier restricts access to only within the same class. It provides the highest level of encapsulation.

Take Test
Q.83 Hard OOP in Java
What is the output?

interface I1 {
void method1();
}
interface I2 extends I1 {
void method2();
}
class C implements I2 {
public void method1() { System.out.println("M1"); }
public void method2() { System.out.println("M2"); }
}
public class Test {
public static void main(String[] args) {
I1 obj = new C();
obj.method2();
}
}
A M2
B M1
C Compilation Error
D Runtime Error
Correct Answer:  C. Compilation Error
EXPLANATION

obj is of type I1 which doesn't have method2(). Though actual object C has method2(), reference type determines what methods are accessible.

Take Test
Q.84 Medium OOP in Java
Which of the following statements about 'instanceof' operator is correct?
A It checks if an object is created from a class
B It checks if an object is an instance of a class or interface
C It checks if a variable is static
D It converts object type
Correct Answer:  B. It checks if an object is an instance of a class or interface
EXPLANATION

The 'instanceof' operator checks whether an object is an instance of a specific class or implements a specific interface.

Take Test
Q.85 Hard OOP in Java
What will be the output?

class Test {
int x = 5;
{
x = 10;
}
Test() {
x = 15;
}
public static void main(String[] args) {
Test t = new Test();
System.out.println(t.x);
}
}
A 5
B 10
C 15
D Compilation Error
Correct Answer:  C. 15
EXPLANATION

Instance initializer block executes after variable initialization but before constructor. Constructor executes last, setting x = 15.

Take Test
Q.86 Easy OOP in Java
Which keyword is used to make a variable immutable in Java?
A static
B final
C private
D const
Correct Answer:  B. final
EXPLANATION

'final' keyword makes a variable immutable. Once assigned, its value cannot be changed. 'const' is not a valid Java keyword.

Take Test
Q.87 Medium OOP in Java
What is the output?

class A {
A() {
System.out.println("A");
}
}
class B extends A {
B() {
super();
System.out.println("B");
}
}
public class Test {
public static void main(String[] args) {
new B();
}
}
A B then A
B A then B
C Only B
D Compilation Error
Correct Answer:  B. A then B
EXPLANATION

super() calls parent constructor first. Parent constructor A prints 'A', then child constructor B prints 'B'.

Take Test
Q.88 Easy OOP in Java
Which of the following correctly describes the 'this' keyword?
A Refers to the parent class
B Refers to the current object instance
C Refers to the class itself
D Refers to the method
Correct Answer:  B. Refers to the current object instance
EXPLANATION

'this' is a reference to the current object instance. It's used to refer to instance variables, call other constructors, or pass object reference.

Take Test
Q.89 Hard OOP in Java
What will be the output?

interface A {
void show();
}
class B implements A {
public void show() {
System.out.println("B");
}
}
class C extends B {
public void show() {
System.out.println("C");
}
}
A obj = new C();
obj.show();
A A
B B
C C
D Compilation Error
Correct Answer:  C. C
EXPLANATION

Polymorphism in action. obj is of type A (interface), but actual object is C. C's show() method is called, printing 'C'.

Take Test
Q.90 Medium OOP in Java
What is the correct way to prevent a class from being inherited in Java?
A Mark it as 'private'
B Mark it as 'final'
C Mark it as 'abstract'
D Mark it as 'static'
Correct Answer:  B. Mark it as 'final'
EXPLANATION

The 'final' keyword prevents a class from being extended. String, Integer, and other wrapper classes are marked final for security and immutability.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips