Encapsulation is a process of binding data and code together. 2 Major advantage of encapsulation is security and easy enhancement.
public class Customer {
private String firstName;
private String lastName;
private String debitCard;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getDebitCard() {
return debitCard;
}
public void setDebitCard(String debitCard) {
this.debitCard = debitCard;
}
}
public class Test {
public static void main(String[] args) {
Customer c = new Customer();
c.setFirstName("dev");
c.setLastName(".to");
c.setDebitCard("1234");
System.out.println(c.getFirstName()+" "+c.getLastName()+" "+c.getDebitCard());
}
}
Output - dev .to 1234
Top comments (0)