Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

encapsulation in java

public class Person {

    private String name;
    private int age;

    public  void setName(String name) {
        this.name = name;
    }
    public String getName() {
        return name;
    }
}
//parent class
public class Test {
    public static void main(String[] args) {
        Person p1 = new Person();
        p1.setName("Sabbir");
        System.out.println(p1.getName());

    }
}
 
PREVIOUS NEXT
Tagged: #encapsulation #java
ADD COMMENT
Topic
Name
1+7 =