what is encapsulation in java

Solutions on MaxInterview for what is encapsulation in java by the best coders in the world

showing results for - "what is encapsulation in java"
Luna
02 May 2019
1// java program on encapsulation
2class EncapsulationExample
3{
4   private int ID;
5   private String stuName;
6   private int stuAge;
7   // getter and setter methods
8   public int getStudentID()
9   {
10      return ID;
11   }
12   public String getStudentName()
13   {
14      return stuName;
15   }
16   public int getStudentAge()
17   {
18      return stuAge;
19   }
20   public void setStudentAge(int number)
21   {
22      stuAge = number;
23   }
24   public void setStudentName(String number)
25   {
26      stuName = number;
27   }
28   public void setStudentID(int number)
29   {
30      ID = number;
31   }
32}
33public class ExampleForEncapsulation
34{
35   public static void main(String[] args)
36   {
37      EncapsulationExample student = new EncapsulationExample();
38      student.setStudentName("Virat");
39      student.setStudentAge(5);
40      student.setStudentID(2353);
41      System.out.println("Student Name: " + student.getStudentName());
42      System.out.println("Student ID: " + student.getStudentID());
43      System.out.println("Student Age: " + student.getStudentAge());
44   }
45}
Alexander
02 Nov 2020
1Encapsulation focus on Private Data
2Encapsulation allows the programmer to hide 
3and restrict access to data. 
4To achieve encapsulation:
51.Declare the variables with the private access modifier
62.Create public getters and setters that allow indirect 
7access to those variables
8 
9Framework Example:
10In my project I created multiple POJO/BEAN classes in order 
11to manage test data and actual data. 
12I take JSON from API response and convert 
13to object of my POJO class. 
14All the variables are private with getters and setter. 
15Also in order to store credentials or sensitive data 
16in my framework I have use encapsulation, configuration reader 
17also known as property file or excel sheet to hide data 
18from the outside. I use Apache POI if the data is stored in Excel 
19in order to extract/read and modify data.
20Partial Encapsulation Usage / getters and setters have to be Public
21We can provide only getters in a class to make the class immutable. 
22(Read only) returning private instance variable thats all
23We provide setters in a class to make the class attribute write-only,
24and return type is void just initialize the given argument
Luka
28 Mar 2020
11-ENCAPSULATION: We can hide direct access to data by using
2private key and we can access private data by using getter and
3setter method.
queries leading to this page
how do we achieve encapsulationdefinition of encapsulation in javawat is encapsulationencapsulation meanign encapsulation java 5csimple java program with encapsulated classwhat is encapsulation in jacawhat is encapsulation code example in javaencapsulation exampleshow do we achieve encapsulation in javaencapsulation in java examplewhat is the purpose of encapsulation in ajvaabstraction and encapsulation in java with exampleencapsulation in java with realtime exampleencapsulation in java with exampledata encapsulation example in javaencapsulation using javajava why encapsulation is neededencapsulation definationencapsulation java definitionencapsulation in javawhich of the following describes encapsulationjava encapsularjava encapsulationencapsulation exampleencapsulation in java programsencapsulation in java languagebenefits of encapsulation in javawhat is encapsulation and how did you use it 3fexample of encapsulation in javadefine encapsulation in javatypes of encapsulation in javaencapsulation and compositionencapsulation definitiomencapsulated javade encapsulationencapsulation definition javathe basic unit of encapsulation in java is theencapsulation in oops javaproper encapsulation in javaencapsulate definitionencapsulation in programmingencapsulation example in javawhat is encapsulation and how does java implement it 3fwhat is encaptulation in javawhat is the use of encapsulation in javaencapsulation explained javaencapsulation principle in javause of encapsulation in javahow can we achieve encapsulation in javajava programs for encapsulationjava encapsulation syntaxwhy we use encapsulationwhat is encapsulationexample for encapsulation in javaexample of encapsulationwritten example of encapsulationjava encapsulate meaningencapsulation in programming meaningprogram showing encapsulation in javaencapsulation meaning javaencapsulate javahow is encapsulation achieved in java programmingencapsulation example in java codeencapsulation programminghow can we achieve encapsulationhow is encapsulation implemented in javaencapsulation helps in writing which classes in javaencapsulation why do we use encapsulation in javawhat do you mean by encapsulationadvantages of encapsulation in javawhy encapsulationwhat does encapsulate meanencapsulation defineencapsulation definitiondefine encapsulation disadvantages of encapsulation in javawhat encapsulationthe basic unit of encapsulation in java is the 3ademonstrate encapsulationmeaning of encapsulation javaencapsulation in java real time exampleencapsulation in javaencapsulation iencapsulation implementation in javaencapsulation meaning in programmingencapsulate meaning in javaencapsulation definition in javawhy we need encapsulation in javaencapsulation example gfgencapsulation with exampleencapsulamento java exampleswhat is encapsulation in java with real life examplewhat is java encapsulationsimportance of encapsulation in javaencapsulation in java what is explain encapsulationwhat is encapsulated javawhy we use encapsulation in javaencapsulation in jvaencapsulation in java with example programsjava full fully encapsulationencapsulation program in javadefinition of encapsulationwhat is encapsulation in java with exampleencapsulation in java isencapsulation en javahow to achieve encapsulation in javawhat is encapsulation javaencapsulation meanswhats is encapsulation in javaencapsulation is used inencapsultation in javahow can we achieve encapsulation in java with example 3fencapsulation concept in java isto achieve encapsulation in javawhat does encapsulation mean 3fjava what is encapsulationencapsulation definition iwhen we used encapsulationabstraction and encapsulation in javaexamples of encapsulation in jvaaencapsulation in java as a programencapsulation in c 2b 2b and javaexamples of encapsulation in javaencapsulation examples javawhat is encapsulation 3f explain with an example types of encapsulationencapsulation injavaencapsulation javain which encapsulation occursdoes protected comes under encapsulation in javajava encapsulation exampleencapsulation java exampleencapsulation meaningencapsulation in java useswhat does encapsulation meanencapsulation means security 3fprogramming encapsulationencapsulation and decapsulationwhy encapsulation is used in javaencapsulation and abstraction in javawhat does encapsule meanencapsulation in java meaningexample of naming encapsulation in java isencapsulation ofhow we can achieve encapsulation in javavoid and encapsulation javawhat is encapsulation 3f javaencapsulation example javaencapsulation java codejava encapsulation protectedwhat is the purpose of encapsulation in javaencapsulation in ajvaencapsulation in java guihow to do encapsulationencapsulate in javaencapsulation in java codeencapsulationencapsulation meaning in javawrite a program to show the implementation of encapsulation in java encapsulation meanexample of encapsulation javause of encapsulationencapsulamiento en javahow to achieve encapsulationwhy encapsulation is used for in javawhat is encapsulation in java 3fencapsulacion javawhat is java encapsulationfollowing concept can be used for encapsulation in java programsencapsulation java educativecomplete encapsulation javahow to achieve encapsulation in java 3f give an example complete encapsulation in javahow encapsulation works in javaexamples of encapsulation javaa java class is the example of encapsulationencapsulation isin java is a mechanism to encapsulate ajava function encapsulationwhy we create encapsulation in javaencapsulation in java programizwhat is encapsulation in javahow is encapsulation achieved in javaimplement encapsulation in javaencapsulation in programallintitle 3aencapsulation in javahow interface encapsulation javaencapsular en javadefine encapsulationencapsulation in java example diagramencapsulation class in javain java encapsulation in javadefinition of encapsulation in programmingjava program for encapsulation and abstractionwhy is encapsulation usedhow to encapsulation in javaencapsulacion en javahow to use encapsulation in javawhat is encapsulation in java