/* Employee.java */ package mypack; import java.io.*; public class Employee { private int empid; private String ename; private double sal; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); public void getData() { try { System.out.println("Enter Employee ID: "); empid=Integer.parseInt(br.readLine()); System.out.println("Enter Employee Name: "); ename=br.readLine(); System.out.println("Enter Employee Salary: "); sal=Double.valueOf(br.readLine()); } catch(Exception e) { System.err.println(e); } } public void showData() { System.out.println("\tEmployee Details\n"); System.out.println("\tEmployee ID: "+empid); System.out.println("\tEmployee Name: "+ename); System.out.println("\tEmployee Salary: "+sal); } }
After compiling above code, "Employee.class" file will be generated. Create a new folder and name it as "mypack" in the same location of your program and copy the "Employee.class" file in the folder.
Place the below code outside "mypack" and run it
/* Test.java */ import mypack.Employee; class Main { public static void main(String[] args) { Employee ob=new Employee(); ob.getData(); ob.showData(); System.out.println("Employee package is used"); } }
Output |
No comments:
Post a Comment