Java Encapsulation
Example ::
package Encapsulation; public class Person { private String name , gender; private int age; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } }
Run Example Main Class ::
package Encapsulation; public class RunPerson { public static void main(String[] args) { SetterAndGetter sg = new SetterAndGetter(); sg.setName("Shafiqul Islam"); sg.setGender("Mail"); sg.setAge(33); System.out.println(sg.getName()); System.out.println(sg.getGender()); System.out.println(sg.getAge()); } }
No comments:
Post a Comment
I am Safiqul Islam Tuhin