Java Programming
Java OOP, collections, multithreading
270 Questions 10 Topics Take Test
Advertisement
Showing 221–230 of 270 questions
Q.221 Easy OOP in Java
Which access modifier allows a member to be accessed only within the same class?
A public
B private
C default
D protected
Correct Answer:  B. private
EXPLANATION

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

Take Test
Q.222 Easy OOP in Java
Consider the code:
class A { A() { System.out.println("A"); } }
class B extends A { B() { super(); System.out.println("B"); } }
What will be printed when 'new B()' is executed?
A B then A
B A then B
C Only B
D Compilation Error
Correct Answer:  B. A then B
EXPLANATION

The super() call invokes the parent class constructor first, printing 'A', then the child constructor completes, printing 'B'.

Take Test
Q.223 Easy OOP in Java
What is the primary purpose of the 'super' keyword in Java?
A To create an instance of the parent class
B To access parent class methods and constructors
C To declare a variable as final
D To implement multiple inheritance
Correct Answer:  B. To access parent class methods and constructors
EXPLANATION

The 'super' keyword is used to refer to parent class methods, constructors, and variables. It allows a child class to access parent class members.

Take Test
Q.224 Easy OOP in Java
What will be the output of the following code?
class Parent { void display() { System.out.println("Parent"); } }
class Child extends Parent { void display() { System.out.println("Child"); } }
public class Test { public static void main(String[] args) { Parent p = new Child(); p.display(); } }
A Child
B Parent
C Compilation Error
D Runtime Error
Correct Answer:  A. Child
EXPLANATION

This demonstrates runtime polymorphism. Even though p is a Parent reference, it points to a Child object, so the overridden display() method in Child class is executed.

Take Test
Q.225 Easy OOP in Java
Which of the following correctly describes the relationship between a class and an interface?
A A class extends an interface
B An interface implements a class
C A class implements an interface
D Both are interchangeable terms
Correct Answer:  C. A class implements an interface
EXPLANATION

In Java, a class implements an interface. A class extends another class. An interface can extend another interface. This is the correct terminology and relationship structure.

Take Test
Q.226 Easy OOP in Java
In Java OOP, which principle ensures that internal details of a class are hidden from the outside world?
A Inheritance
B Polymorphism
C Encapsulation
D Abstraction
Correct Answer:  C. Encapsulation
EXPLANATION

Encapsulation is the bundling of data and methods into a single unit (class) while hiding internal implementation details using access modifiers.

Take Test
Q.227 Easy OOP in Java
What is the primary purpose of using the 'super' keyword in Java?
A To create an object of parent class
B To access parent class methods and constructors
C To prevent method overriding
D To declare a variable as final
Correct Answer:  B. To access parent class methods and constructors
EXPLANATION

'super' is used to refer to parent class methods, constructors, and variables. It helps in accessing hidden or overridden members of the parent class.

Take Test
Q.228 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.229 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.230 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
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