Encapsulation notes
Encapsulation notes
Sales Team
Sales team contains private data so that finance team can not access the data
directly.
Finance Team
Finance can access the sales data with help of sales superviser(setter &
getter)
ex:
class Emp
{ //private properties
private int eid;
private String ename;
private double esal;
//getters methods used to get the ata : getXXX() xxx = property name
public int getEid()
{ return eid;
}
public String getEname()
{ return ename;
}
public double getEsal()
{ return esal;
}
}
class TestClient
{ public static void main(String[] args)
{ Emp e1 = new Emp();
e1.setEid(111);
e1.setEname("sajida");
e1.setEsal(5000);
ex:
when we set the data using setter methods then get the data using getter methods.
When we set the data using constructor then get the data by overriding toString().
class Emp
{ //private properties
private int eid;
private String ename;
private double esal;
class TestClient
{ public static void main(String[] args)
{ Emp e1 = new Emp(111,"ratan",10000.45);
System.out.println(e1);
Assignment:
class Student
{ sid,sname,email,standard
setter methods set the data
getter methods get the data
}
class TestClient
{ public static void main(String[] args)
{ create the object set the values
get the values using getters