Java Programming — OOP in Java
Java OOP, collections, multithreading
100 Questions 10 Topics Take Test
Advertisement
Showing 91–100 of 100 questions in OOP in Java
Q.91 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.

Take Test
Q.92 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.

Take Test
Q.93 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.

Take Test
Q.94 Easy OOP in Java
Which interface in Java represents a collection that does not allow duplicate elements?
A List
B Set
C Queue
D Map
Correct Answer:  B. Set
EXPLANATION

Set interface ensures uniqueness and doesn't allow duplicate elements. HashSet, TreeSet are implementations of Set.

Take Test
Q.95 Easy OOP in Java
What is the purpose of the 'super' keyword in Java?
A To refer to the current object
B To refer to the parent class members
C To create a new object
D To call static methods
Correct Answer:  B. To refer to the parent class members
EXPLANATION

The 'super' keyword is used to refer to the immediate parent class object. It's used to access parent class methods and constructors.

Take Test
Advertisement
Q.96 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.

Take Test
Q.97 Easy OOP in Java
What will be the output?

class Parent {
void show() {
System.out.println("Parent");
}
}
class Child extends Parent {
void show() {
System.out.println("Child");
}
}
parent obj = new Child();
obj.show();
A Parent
B Child
C Compilation Error
D Runtime Error
Correct Answer:  B. Child
EXPLANATION

This demonstrates method overriding and polymorphism. The actual object type is Child, so Child's show() method is called.

Take Test
Q.98 Easy OOP in Java
Which access modifier allows a member to be accessed only within the same package?
A public
B private
C protected
D default (package-private)
Correct Answer:  D. default (package-private)
EXPLANATION

Default access (no modifier) allows access only within the same package. Protected allows same package and subclasses.

Take Test
Q.99 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.

Take Test
Q.100 Easy OOP in Java
Which of the following is NOT a pillar of Object-Oriented Programming?
A Abstraction
B Polymorphism
C Compilation
D Encapsulation
Correct Answer:  C. Compilation
EXPLANATION

The four pillars of OOP are Abstraction, Encapsulation, Inheritance, and Polymorphism. Compilation is a process, not a pillar of OOP.

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