Employee.java public class Employee { private String cnic; private String name; private double salary; public Employee() { System.out.println("No-argument constructor called"); } public Employee(String cnic, String name) { setCnic(cnic); setName(name); } public Employee(String cnic, String name, double salary) { this(cnic,name); setSalary(salary); } public String getCnic() { return cnic; } public void setCnic(String cnic) { this.cnic = cnic; } public String getName() { return name; } public void setName(String name) { this.name = name; } public double getSalary() { return salary; } public void setSalary(double salary) { this.salary = salary; } public void getEmployee(){ System.out.println("CNIC: " + cnic); System.out.println("Name: " + name); System.out.println("Salary: " + salary); } } /////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// EmployeeTest.java public class EmployeeTest { public static void main(String[] args) { System.out.println(); Employee employee1 = new Employee(); Employee employee2 = new Employee("34104-1234567-9","Muhammad Abdul Rehman"); Employee employee3 = new Employee("34104-9876543-2","Ahmad",100000); employee1.getEmployee(); System.out.println("----------------"); employee2.getEmployee(); System.out.println("-----------------"); employee3.getEmployee(); System.out.println("-----------------"); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter