Encapsulation Program in Java
Advertisements
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
Google Advertisment