Q. Explain Encapsulation with program example. .
The wrapping up of data and methods into a single unit ( called class ) is known as Encapsulation . Data Encapsulation is one of the most striking and important features of OOPS.
The data is not accesible to the outside world and only those methods which are wrapped in the class can access it . These methods provide the interface between the objects data and the program. This insulation of data from direct access by the program is called Data hiding. Encapsulation makes it possible for objects to be treated like black boxes, each performing a specific task without any concern for internal implementation. Example :
Class student
{
public int roll;
public char name[100];
private fees;
public void student()
{
System.out.println("First Class ");
}
}
public class example
{
public static void main(String args[])
{
student obj = new student ();
obj.student();
System.out.println("The First Program");
}
}