zoukankan      html  css  js  c++  java
  • 18

    package room1;
    class Employee{

    String name;
    int age;
    String designation;
    double salary;

    // This is the constructor of the class Employee
    public Employee(String name){
    this.name = name;
    }
    // Assign the age of the Employee to the variable age.
    public void empAge(int empAge){
    age = empAge;
    }
    /* Assign the designation to the variable designation.*/
    public void empDesignation(String empDesig){
    designation = empDesig;
    }
    /* Assign the salary to the variable salary.*/
    public void empSalary(double empSalary){
    salary = empSalary;
    }
    /* Print the Employee details */
    public void printEmployee(){
    System.out.println("Name:"+ name );
    System.out.println("Age:" + age );
    System.out.println("Designation:" + designation );
    System.out.println("Salary:" + salary);
    }


    public static void main(String args[]){
    /* Create two objects using constructor */
    Employee empOne = new Employee("James Smith");
    Employee empTwo = new Employee("Mary Anne");

    // Invoking methods for each object created
    empOne.empAge(26);
    empOne.empDesignation("Senior Software Engineer");
    empOne.empSalary(1000);
    empOne.printEmployee();

    empTwo.empAge(21);
    empTwo.empDesignation("Software Engineer");
    empTwo.empSalary(500);
    empTwo.printEmployee();
    }
    }

  • 相关阅读:
    LA3971组装电脑
    LA3971组装电脑
    LA3905流星
    LA3905流星
    LA3902网络
    LA3902网络
    LA3708墓地雕塑
    洛谷 P2330 [SCOI2005]繁忙的都市(最小生成树)
    最小生成树 & 洛谷P3366【模板】最小生成树 & 洛谷P2820 局域网
    洛谷 P1372 又是毕业季I
  • 原文地址:https://www.cnblogs.com/acm-icpcer/p/6536317.html
Copyright © 2011-2022 走看看