encapsulation in java

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

showing results for - "encapsulation in java"
Rafaela
16 Apr 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}
Giorgio
16 Sep 2016
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
Chiara
28 Jan 2017
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
java what is encapsulationdefine encapsulation in javademonstrate encapsulationencapsulation example in java codeallintitle 3aencapsulation in javaencapsulation encapsulation helps in writing which classes in javajava function encapsulationwhy do we use encapsulation in javahow is encapsulation achieved in java programmingencapsulation meansencapsulate definitionencapsulation example gfgencapsulation definitionencapsulation in ajvawhat is encapsulation in javaencapsulation java 5cwhat is encapsulation code example in javadoes protected comes under encapsulation in javaencapsulation in java codeexample of encapsulation in javaencapsulation definationencapsulation in functionencapsulation definition javaencapsulacion javaabstraction and encapsulation in javaencapsulation explained javawhat is encapsulation javaencapsulation in java with realtime exampleencapsulation idefine encapsulation encapsulation examples javajava programs for encapsulationencapsulation meanign encapsulacion en javahow to achieve encapsulation in javahow can we achieve encapsulationwhat is encapsulation and how does java implement it 3fabstraction and encapsulation in java with examplein java is a mechanism to encapsulate aencapsulation meaning in javaexamples of encapsulation javahow we can achieve encapsulation in javawhat does encapsulate meanwhat is encapsulation in java with exampleencapsulation definition iencapsulation injavawhat does encapsulation meantypes of encapsulationencapsulation in java with examplewhy encapsulation is used in javawhat is encapsulation 3f javadata encapsulation example in javaencapsulation is a techniquehow interface encapsulation javaencapsulation in java what is encapsulation isencapsulamento java exampleswhy encapsulation in javaa java class is the example of encapsulationdefine encapsulationencapsulation meanuse of encapsulationwhat is java encapsulationde encapsulationencapsulation in java exampleencapsulation exampleadvantages of encapsulation in javaencapsulation java educativeexample of naming encapsulation in java isexamples of encapsulation in javaexample of encapsulationencapsulation examplesencapsulation in programjava full fully encapsulationencapsulation en javaencapsulation problem javal 27encapsulation javaencapsulation and abstraction in javahow can we achieve encapsulation in java with example 3fhow to achieve encapsulationhow is encapsulation achieved in javajava encapsulation exampleuse of encapsulation in javato achieve encapsulation in javahow to encapsulation in javaencapsulation java que esprogramming encapsulationencapsulation in java with example programswhat is java encapsulationsexplain encapsulationencapsulation ofencapsulation and compositionwhat is encapsulation in java 3fhow to use encapsulation in javajava why encapsulation is neededencapsulation definition in javawhat is the use of encapsulation in javaencapsulation in oops javacomplete encapsulation in javaencapsulation in jvaexample of encapsulation javawhat is encaptulation in javajava encapsularhow encapsulation works in javaencapsulation in java meaningtypes of encapsulation in javain java encapsulation in javawhat encapsulationencapsulation in programming meaningdefinition of encapsulation in javain which encapsulation occurspurpose of encapsulation in javaencapsulation java codewhy we use encapsulation in javawhat is the purpose of encapsulation in ajvahow do we achieve encapsulation in javaencapsulamiento en javawhat is encapsulation 3f explain with an example how to achieve encapsulation in java 3f give an example encapsulation means security 3fhow do we achieve encapsulationjava encapsulate meaningwhy is encapsulation usedhow can we achieve encapsulation in javaencapsulation example in javawat is encapsulationvoid and encapsulation javaexample for encapsulation in javaencapsulation example javawhat is encapsulationencapsulation in java usescomplete encapsulation javaexamples of encapsulation in jvaaproper encapsulation in javafollowing concept can be used for encapsulation in java programswhy we create encapsulation in javawhat is the purpose of encapsulation in javaencapsular en javadefinition of encapsulation in programmingbenefits of encapsulation in javaencapsulation in programmingwhat does encapsule meanencapsulation in java programsjava program for encapsulation and abstractionwhy we need encapsulation in javawhat do you mean by encapsulationimplement encapsulation in javajava encapsulation definitionencapsulate in javaencapsulation meaning javawhen we used encapsulationencapsulation and decapsulationencapsulationencapsulation principle in javaencapsulation in javathe basic unit of encapsulation in java is the 3awhy encapsulationwhy we use encapsulationencapsulation in java real time exampleencapsulation class in javawhats is encapsulation in javawhy encapsulation is used for in javaencapsulation in java languageimportance of encapsulation in javaencapsulation in java code exampleencapsulated javaencapsulation is used inwhat is encapsulation in java with real life exampleencapsulate meaning in javaencapsulation protected javaencapsulation in java as a programjava encapsulation utilitymeaning of encapsulation javaencapsulation defineencapsulation using javaencapsulation java exampleprogram showing encapsulation in javajava encapsulationwrite a program to show the implementation of encapsulation in java what is encapsulated javaencapsulation concept in java isencapsulation in java iswhat is encapsulation in jacahow is encapsulation implemented in javaencapsulation meaningwhich of the following describes encapsulationencapsulation in c 2b 2b and javathe basic unit of encapsulation in java is theencapsulation implementation in javaencapsultation in javaencapsulation program in javaencapsulation with exampleencapsulation in java example diagramwhat does encapsulation mean 3fwritten example of encapsulationencapsulation in java guijava encapsulation protectedencapsulation in java programizhow to do encapsulationencapsulation in javasimple java program with encapsulated classdisadvantages of encapsulation in javadefinition of encapsulationencapsulation meaning in programmingencapsulate javaencapsulation java definitionencapsulation definitiomencapsulation programmingwhat is encapsulation and how did you use it 3fjava encapsulation syntaxencapsulation javaencapsulation in java