Encapsulation Interview Questions in Java


Prev Tutorial Next Tutorial

Interview Questions on Encapsulation in Java

Why use Encapsulation ?

Encapsulation in java is a process of wrapping code and data together into a single unit.

Real life example of Encapsulation ?

Real life example of encapsulation is; capsule is mixed of several medicines.

Advantage of Encapsulation in java ?

  • Encapsulated Code is more flexible and easy to change with new requirements.
  • Encapsulation in Java makes unit testing easy.
  • Encapsulation in Java allows you to control who can access what.
  • Encapsulation allows you to change one part of code without affecting other parts of code.

What are the features of encapsulation ?

Combine the data of our application and its manipulation at one place.

What is difference between Encapsulation And Abstraction ?

Abstraction solves the problem at design level while encapsulation solves the problem at implementation level.

Which of the following Java feature promotes access protection or Hiding ?

  • Inheritance
  • Encapsulation
  • Abstraction
  • Composition

Ans: Encapsulation

What is difference between Encapsulation and Abstraction ?

AbstractionEncapsulation
Abstraction solves the problem at design level.Encapsulation solves the problem at implementation level
It is used for hiding the unwanted data and giving relevant data.hiding the code and data into a single unit to protect the data from outside world.
It focus on what the object does instead of how it does it.It hiding the internal details or mechanics of how an object does something.
Outer Look of a Television, like it has a display screen and channel buttons to change channel it explains Abstraction.but Inner Implementation detail of a Television how CRT and Display Screen are connect with each other using different circuits , it explains Encapsulation.

Prev Tutorial Next Tutorial

Advertisements




Download Projects