Implements the Concept of Encapsulation.
Source Code:
class Emp
{
private int empid;
private String name;
public Emp( int x,String y)
{
empid=x;
name=y;
}
public void show()
{
System.out.println("empid="+empid);
System.out.println("name="+name);
}
}
class Encap
{
public static void main(String arg[])
{
int eid=Integer.parseInt(arg[0]);
String ename=arg[1];
Emp e1=new Emp(eid,ename);
e1.show();
}
}
Output:
empid=2
name=Asish
<<Previous Page Download Code Next Page>>
Related JAVA Programs:
- Write a JAVA program to print "Hello World".
- Write a JAVA program to find sum of all integer greater than 100 and less than 200, that are divisible by 5.
- Write a JAVA program to show how method overriding helps in dynamic method dispatch.
- Write a JAVA program to Serach and Delete a specific element from an integer array.
- Write a JAVA program to illustrate how super keyword is used to call the parent class constructor within the child class.
- Write a JAVA program illustrating parameterized constructor.
- Write a Java program to discuss the difference between Break and Continue.
- Write a JAVA program to create and access a user defined packages.
- Write a JAVA program to calculate the length of a string.
- Write a JAVA program to findout the number of Vowels present in the input string.
- JAVA Program that implements the Concept of Encapsulation.