Loading

Quipoin Menu

Learn • Practice • Grow

java / Java Encapsulation
mcq

Q1.

What is the main purpose of encapsulation in Java?

A. To allow multiple inheritance

B. To hide data and provide controlled access

C. To increase runtime performance

D. To make variables global

Q2.

Which access modifier is commonly used to achieve encapsulation in Java?

A. public
B. private
C. protected
D. default

Q3.

How can external classes access encapsulated data in Java?

A. Directly accessing private variables

B. Using getter and setter methods

C. Using constructors only

D. By inheritance

Q4.

Which of the following best demonstrates encapsulation?

A. Using extends keyword

B. Declaring variables as public

C. Wrapping data and methods inside a class

D. Overriding methods in subclass

Q5.

What will happen if a class has private variables but no getters or setters?

A. Compilation error

B. Variables can still be accessed from outside

C. Variables are completely hidden and inaccessible from outside

D. JVM automatically generates getters and setters