Java Programming — OOP in Java
Java OOP, collections, multithreading
100 Questions 10 Topics Take Test
Advertisement
Showing 41–50 of 100 questions in OOP in Java
Q.41 Medium OOP in Java
What is the difference between 'this' and 'super' keywords?
A 'this' refers to parent class and 'super' refers to current class
B 'this' refers to current class instance and 'super' refers to parent class
C They are interchangeable
D 'super' is used only in abstract classes
Correct Answer:  B. 'this' refers to current class instance and 'super' refers to parent class
EXPLANATION

'this' is a reference to the current object instance, while 'super' is a reference to the parent class. They serve different purposes in inheritance hierarchy.

Take Test
Q.42 Medium OOP in Java
Which of the following statements about the 'final' keyword is correct?
A A final class can be extended
B A final method can be overridden
C A final variable's value cannot be changed after initialization
D A final class can implement multiple interfaces
Correct Answer:  C. A final variable's value cannot be changed after initialization
EXPLANATION

The 'final' keyword when applied to a variable makes it a constant. When applied to a class, it cannot be extended. When applied to a method, it cannot be overridden.

Take Test
Q.43 Easy OOP in Java
Can a class extend multiple classes in Java?
A Yes, using multiple inheritance
B No, Java supports only single inheritance
C Yes, but only if they are abstract classes
D Yes, using the 'extends' keyword multiple times
Correct Answer:  B. No, Java supports only single inheritance
EXPLANATION

Java supports only single class inheritance to avoid the diamond problem. However, multiple interface implementation is allowed.

Take Test
Q.44 Medium OOP in Java
What is the output of the following code?
class Parent { void show() { System.out.println("Parent"); } }
class Child extends Parent { void show() { System.out.println("Child"); } }
public class Test { public static void main(String[] args) { Parent p = new Child(); p.show(); } }
A Parent
B Child
C Compile-time error
D Runtime error
Correct Answer:  B. Child
EXPLANATION

This demonstrates runtime polymorphism. Although the reference is of type Parent, the actual object is Child. The overridden show() method in Child class is executed.

Take Test
Q.45 Easy OOP in Java
Which keyword is used to achieve runtime polymorphism in Java?
A final
B static
C virtual
D None of the above
Correct Answer:  D. None of the above
EXPLANATION

Java achieves runtime polymorphism through method overriding using inheritance. Unlike C++, Java doesn't use the 'virtual' keyword; it's implicit for all non-final methods.

Take Test
Advertisement
Q.46 Easy OOP in Java
What happens when you try to instantiate an interface in Java?
A It creates an anonymous inner class instance
B It throws a compile-time error
C It throws a runtime error
D It works like a normal class instantiation
Correct Answer:  B. It throws a compile-time error
EXPLANATION

Interfaces cannot be instantiated directly. You must create a concrete class that implements the interface or use an anonymous inner class.

Take Test
Q.47 Medium OOP in Java
Which statement is true about the default access modifier (package-private) in Java?
A Members are accessible from any package
B Members are accessible only within the same package
C Members are accessible only within the same class
D Members are not accessible anywhere
Correct Answer:  B. Members are accessible only within the same package
EXPLANATION

The default (package-private) access modifier allows access to members from any class within the same package, but not from classes in other packages.

Take Test
Q.48 Easy OOP in Java
Which of the following correctly describes encapsulation?
A Wrapping data and methods together and hiding internal details
B Creating multiple classes with same functionality
C Extending one class from another
D Implementing an interface
Correct Answer:  A. Wrapping data and methods together and hiding internal details
EXPLANATION

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

Take Test
Q.49 Hard OOP in Java
What is the main difference between method overriding and method overloading?
A Overriding is for same class, overloading is for different classes
B Overriding changes method signature, overloading keeps it same
C Overriding is runtime polymorphism, overloading is compile-time polymorphism
D Overriding requires final keyword, overloading doesn't
Correct Answer:  C. Overriding is runtime polymorphism, overloading is compile-time polymorphism
EXPLANATION

Method overloading is compile-time (static) polymorphism with same method name but different parameters in the same class. Method overriding is runtime (dynamic) polymorphism where a child class provides a specific implementation of a parent method.

Take Test
Q.50 Medium OOP in Java
Consider the code:
abstract class Animal { abstract void sound(); void sleep() { System.out.println("Zzz"); } }
class Dog extends Animal { void sound() { System.out.println("Bark"); } }
What can Dog objects do?
A Only call sound()
B Only call sleep()
C Call both sound() and sleep()
D Neither sound() nor sleep()
Correct Answer:  C. Call both sound() and sleep()
EXPLANATION

Dog inherits the concrete method sleep() from Animal and provides implementation for the abstract method sound(). Therefore, Dog objects can call both methods.

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