Encapsulation Program in Java

Advertisements

Prev Tutorial Next Tutorial

Encapsulation Example in Java

Encapsulation is the concept of combining data members and function into single unit. Here we write code for Encapsulation using java programming.

Encapsulation Example in Java

class Employee
{  
private String name;  
   
public String getName()
{  
return name;  
}  
public void setName(String name){  
this.name=name;
}  
}  

class Demo
{  
public static void main(String[] args)
{  
Employee e=new Employee();  
e.setName("Harry");  
System.out.println(e.getName());  
} 
}

Output

Salary is: 30000.0
Bonous is: 2000.0

Syntax to compile and run java program

Syntax

for compile -> c:/>javac Employee.java
for run -> c:/>java Employee

For more derails about Inheritance in Java


Prev Tutorial Next Tutorial

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements