Java Encapsulation Concept not clear

后端 未结 12 2404
死守一世寂寞
死守一世寂寞 2020-11-30 03:40

This is basic question but still i don\'t understand encapsulation concept . I did\'t understand how can we change the properties of class from other class.because whenever

12条回答
  •  醉酒成梦
    2020-11-30 04:09

    ENCAPSULATION is mechanism of wrapping methods and variables together as a single unit. for example capsule i.e. mixed of several medicines.

    variables of a class will be hidden from other classes as it will be declared private, and can be accessed only through the methods of their current class

    To achieve encapsulation in Java − * Declare the variables of a class as private. * Provide public setter and getter methods to modify and view the variables values. * The Java Bean class is the example of fully encapsulated class.

提交回复
热议问题