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 11–20 of 27
Topics in Java Programming
Q.11 Easy OOP in Java
Which concept best describes the relationship between Parent and Child classes in 'class Child extends Parent'?
A Composition
B Aggregation
C Inheritance
D Encapsulation
Correct Answer:  C. Inheritance
EXPLANATION

The 'extends' keyword creates an inheritance relationship where Child inherits properties and methods from Parent. This is an 'is-a' relationship.

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

Test
Q.13 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'.

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

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

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

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

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

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

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

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