Computer Science, asked by Aaryan102604, 1 year ago

Hey there...how r u??


What is Encapsulation???​

Answers

Answered by acquinaldrin
7

GEEKSFORGEEKS

Encapsulation in Java

Encapsulation is defined as the wrapping up of data under a single unit. It is the mechanism that binds together code and the data it manipulates.Other way to think about encapsulation is, it is a protective shield that prevents the data from being accessed by the code outside this shield.

Technically in encapsulation, the variables or data of a class is hidden from any other class and can be accessed only through any member function of own class in which they are declared.

As in encapsulation, the data in a class is hidden from other classes, so it is also known as data-hiding.

Encapsulation can be achieved by: Declaring all the variables in the class as private and writing public methods in the class to set and get the values of variables.

Encapsulation

// Java program to demonstrate encapsulation

public class Encapsulate

{

// private variables declared

// these can only be accessed by

// public methods of class

private String geekName;

private int geekRoll;


Aaryan102604: Sir... I also could have Google instead of waiting my 10 points
Aashika3103: hmmm... right
Answered by Anshu33845
0

Answer:

The Basic concept of encapsulation says that data flows down the protocol hierarchy, headers (and trailers) get appended to it and data moves up the hierarchy headers (and trailers) get stripped off.

Similar questions