[go: up one dir, main page]

0% found this document useful (0 votes)
50 views4 pages

Java OOP Quiz 20 Questions Final

The document is a Java OOP quiz focusing on the concepts of encapsulation, inheritance, and polymorphism. It includes multiple-choice questions that test knowledge on topics such as data hiding, class inheritance, and method overriding. Each section contains questions that assess understanding of key principles and risks associated with each OOP concept.

Uploaded by

Harsh Goenka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views4 pages

Java OOP Quiz 20 Questions Final

The document is a Java OOP quiz focusing on the concepts of encapsulation, inheritance, and polymorphism. It includes multiple-choice questions that test knowledge on topics such as data hiding, class inheritance, and method overriding. Each section contains questions that assess understanding of key principles and risks associated with each OOP concept.

Uploaded by

Harsh Goenka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Java OOP Quiz - Encapsulation, Inheritance, Polymorphism

ENCAPSULATION

1. What is encapsulation in Java?

a. Binding data and functions together

b. Hiding implementation details

c. Both a and b

d. Only a

2. Why do we use getters and setters?

a. To break encapsulation

b. To allow direct field access

c. To control access to variables

d. To overload constructors

3. Which of the following best supports encapsulation?

a. abstract classes

b. public fields

c. private fields with public methods

d. final methods

4. What is data hiding in the context of encapsulation?

a. Deleting data

b. Hiding internal variables from other classes

c. Encrypting fields

d. Making methods final

5. Which of the following is a breach of encapsulation?

a. Using private fields with getters

b. Returning a direct reference to a mutable object field

c. Hiding constructor logic

d. Declaring fields private final

6. Which combination best supports encapsulation and information hiding in Java?

a. public fields and private methods

b. private fields and public methods

c. protected fields and final methods


Java OOP Quiz - Encapsulation, Inheritance, Polymorphism

d. static fields and abstract methods

7. What risk arises when returning a reference to an internal array?

a. Performance lag

b. Index misalignment

c. External code can mutate internal state

d. Compilation fails

INHERITANCE

8. Which keyword is used to inherit a class in Java?

a. implements

b. extends

c. inherits

d. superclass

9. Which of these is not inherited by subclasses?

a. public fields

b. static methods

c. private methods

d. protected methods

10. What is the consequence of improper use of inheritance?

a. Code becomes modular

b. Code becomes tightly coupled and fragile

c. Better readability

d. Faster runtime

11. Which inheritance type is not supported directly by Java?

a. Single

b. Multilevel

c. Multiple

d. Hierarchical

12. Which class cannot be inherited?

a. One with only static methods

b. One marked final


Java OOP Quiz - Encapsulation, Inheritance, Polymorphism

c. One with a constructor

d. One marked abstract

13. What happens if a superclass has a parameterized constructor and the subclass does not explicitly call

it?

a. Compile-time error

b. It calls super() automatically

c. It compiles but fails at runtime

d. JVM auto-generates a call with default values

14. Which of the following cant be inherited?

a. final method

b. static method

c. constructor

d. all the above

POLYMORPHISM

15. Which of the following best demonstrates runtime polymorphism?

a. Method overloading

b. Method overriding

c. Constructor overloading

d. Static imports

16. What does dynamic method dispatch mean?

a. Binding method at compile-time

b. Binding method at runtime based on object

c. Printing objects dynamically

d. Executing constructors

17. Can you override a method with a different return type?

a. Yes, if its a covariant type

b. Yes, any return type

c. No

d. Only if method is static

18. Which version of draw() is invoked here?


Java OOP Quiz - Encapsulation, Inheritance, Polymorphism

Shape s = new Circle();

s.draw();

a. Shapes draw

b. Circles draw

c. Compilation error

d. Depends on compiler

19. Which OOP concept allows object behavior to change based on context?

a. Inheritance

b. Overloading

c. Polymorphism

d. Encapsulation

20. What is the primary advantage of polymorphism in large-scale applications?

a. Reduces interface complexity

b. Improves memory usage

c. Eliminates inheritance needs

d. Enables extensible and maintainable code

You might also like