Home Subjects Java Programming OOP in Java

Java Programming
OOP in Java

Java OOP, collections, multithreading

46 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 41–46 of 46
Topics in Java Programming
Q.41 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.

Test
Q.42 Medium OOP in Java
Which of the following is true about method overloading?
A Methods must have different return types
B Methods must have same name but different parameters
C Methods must be in different classes
D Only constructors can be overloaded
Correct Answer:  B. Methods must have same name but different parameters
EXPLANATION

Method overloading requires methods to have the same name but different parameter lists (number, type, or order of parameters). Return type alone is insufficient.

Test
Q.43 Medium OOP in Java
Which of the following best describes encapsulation?
A Hiding implementation details and providing controlled access through methods
B Creating objects from classes
C Inheriting properties from parent class
D Using multiple methods with the same name
Correct Answer:  A. Hiding implementation details and providing controlled access through methods
EXPLANATION

Encapsulation involves bundling data (variables) and methods, hiding implementation details, and providing public methods for access. It protects data integrity.

Test
Q.44 Medium OOP in Java
What will happen when you try to instantiate an interface in Java?
A It will create an instance successfully
B It will throw a RuntimeException
C It will cause a compilation error
D It depends on the JVM version
Correct Answer:  C. It will cause a compilation error
EXPLANATION

Interfaces cannot be instantiated directly. You must create a class that implements the interface. Attempting this causes a compilation error.

Test
Q.45 Medium OOP in Java
Which of the following statements about abstract classes is TRUE?
A Abstract classes can be instantiated
B Abstract classes cannot have concrete methods
C Abstract classes can have abstract methods and concrete methods
D Abstract classes must extend another abstract class
Correct Answer:  C. Abstract classes can have abstract methods and concrete methods
EXPLANATION

Abstract classes can contain both abstract methods (without implementation) and concrete methods (with implementation). They cannot be instantiated directly.

Test
Q.46 Medium OOP in Java
What is the output of the following code?

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

Variable overriding doesn't work in Java like method overriding. obj.x accesses the variable from reference type A, which has value 10.

Test
IGET
IGET AI
Online · Exam prep assistant
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