Home Subjects Java Programming OOP in Java

Java Programming
OOP in Java

Java OOP, collections, multithreading

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

Test
Q.22 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.

Test
Q.23 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.

Test
Q.24 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.

Test
Q.25 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.

Test
Q.26 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.

Test
Q.27 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.

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