Sign up now
to enroll in courses, follow best educators, interact with the community and track your progress.
Download
Encapsulation
56 plays

More
This describes encapsulation of data and the basis of access specifiers.

Kshethra Annarapu
Hey everyone,I am Kshethra. I really love explaining to someone it somehow turned up to my passion.I'm really happy to fulfill my passion .

U
Unacademy user
Ma'am awesome by the no option for rating
  1. ENCAPSULATION


  2. ENCAPSULATION CONCEPT This is the mechanism of wrapping data and code acting on the data methods together as a single unit. This is called data hiding as one method of a class is not accessible from another class > This way the code is safe from any external Interference. Characteristics: Everyone knows how to access it. Can easily be used without implementation details. No side effects to the code > The basic idea of encapsulation is to keep classes separated and prevent them from having tightly coupled with each other


  3. ACHIEVING ENCAPSULATION AND ITS BENEFITS > To achieve Encapsulation in Java: Declare the variables of a class as private. Provide public setter and getter methods to modify and view the variable values BENEFITS: A class has total control over its fields. The users don't know how the class stores its data .When class changes the datatypes the user need not change the code.


  4. PROGRAM public class Student private String name public String getName) return name public void setName(String name) this.name=name: class Test void setName(String name) public static void main(String argsll) Student s-new Student0; s.setName("SIDDU"); System.out.println(s.getNameO)