Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

java opp

The meaning of Encapsulation, is to make sure that "sensitive" data is hidden from users.
it is like the pojo classes in andorid studio


To achieve this, you must :::
    1. declare class variables/attributes as private
    2. provide public get and set methods to access and update the value of a private variable


example :::
    public class Another {

        private int a;
        private int b;
        private int c;
    
        public Another(int a, int b, int c) {
            this.a = a;
            this.b = b;
            this.c = c;
        }
    
        public Another(){
            // default
        }
    
        public int getA() {
            return a;
        }
    
        public int getB() {
            return b;
        }
    
        public int getC() {
            return c;
        }
    
        public void setA(int a) {
            this.a = a;
        }
    
        public void setB(int b) {
            this.b = b;
        }
    
        public void setC(int c) {
            this.c = c;
        }
    }
 
PREVIOUS NEXT
Tagged: #java #opp
ADD COMMENT
Topic
Name
7+1 =