Java Programming — OOP in Java
Java OOP, collections, multithreading
100 Questions 10 Topics Take Test
Advertisement
Showing 51–60 of 100 questions in OOP in Java
Q.51 Hard OOP in Java
In Java, can you create an object of an abstract class?
A Yes, always
B No, never
C Yes, using anonymous inner class
D Only if it has concrete methods
Correct Answer:  C. Yes, using anonymous inner class
EXPLANATION

Abstract classes cannot be directly instantiated, but you can create objects using anonymous inner classes that implement the abstract methods.

Take Test
Q.52 Hard OOP in Java
What is the output of this code?
class A { int x = 10; }
class B extends A { int x = 20; }
public class Test { public static void main(String[] args) { A a = new B(); System.out.println(a.x); } }
A 10
B 20
C Compilation Error
D Runtime Error
Correct Answer:  A. 10
EXPLANATION

Variable shadowing occurs here. The reference type is A, so a.x accesses A's x field which is 10. Method overriding works with methods, not instance variables.

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

Take Test
Q.54 Medium OOP in Java
Which of the following is true about abstract classes?
A They can have constructors
B They cannot have any concrete methods
C They must be instantiated directly
D They can only have abstract methods
Correct Answer:  A. They can have constructors
EXPLANATION

Abstract classes can have constructors to initialize instance variables. They can contain both abstract and concrete methods, and they cannot be directly instantiated.

Take Test
Q.55 Medium OOP in Java
What is method overloading?
A Defining multiple methods with different parameters but same name
B Defining multiple methods with same parameters and same name
C Creating methods in parent and child classes with same name
D Calling a method multiple times
Correct Answer:  A. Defining multiple methods with different parameters but same name
EXPLANATION

Method overloading allows multiple methods with the same name but different parameters (number, type, or order). It is a compile-time (static) polymorphism.

Take Test
Q.56 Medium OOP in Java
Consider:
interface I1 { void method(); }
interface I2 { void method(); }
class C implements I1, I2 { public void method() { System.out.println("Method"); } }
What will be the behavior?
A Compilation error due to ambiguity
B The single method implementation satisfies both interfaces
C Runtime error
D Only I1's method is implemented
Correct Answer:  B. The single method implementation satisfies both interfaces
EXPLANATION

When a class implements multiple interfaces with the same method signature, a single method implementation satisfies all interfaces. This is resolved at compile time.

Take Test
Q.57 Medium OOP in Java
Which statement about 'this' keyword is correct?
A It always refers to the parent class
B It refers to the current instance of the class
C It is used only in static methods
D It cannot be used in constructors
Correct Answer:  B. It refers to the current instance of the class
EXPLANATION

'this' is a reference variable that refers to the current object instance. It is commonly used to distinguish instance variables from parameters with the same name.

Take Test
Q.58 Medium OOP in Java
What will happen if you try to override a final method in a child class?
A It will compile successfully
B Compilation error will occur
C Runtime error will occur
D The final keyword will be ignored
Correct Answer:  B. Compilation error will occur
EXPLANATION

Final methods cannot be overridden. The compiler will throw an error indicating that you cannot override a final method.

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