java创建一个员工类,包含姓名,出生年份两个属性,利用构造方法给实例属性附值,
1个回答
关注
展开全部
咨询记录 · 回答于2021-11-22
java创建一个员工类,包含姓名,出生年份两个属性,利用构造方法给实例属性附值,
用Java编写一个员工类程序:1.属性:员工编号,员工姓名,基本工资,奖金,2.构造方法:至少两个。如下:package com.test;public class Employee { private String number; private String name; private double salary; public Employee() { } public Employee(String number, String name, double salary) { super(); this.number = number; this.name = name; this.salary = salary; } public static void main(String[] args) { //员工一,并且构造函数里设置值 Employee e1 = new Employee("e0001", "xiaoming", 5000.0); System.out.println("员工一:" + e1); //员工二,用set设置值,get的话可以获取到员工某个属性 Employee e2 = new Employee(); e2.setName("小二"); e2.setNumber("e0002"); e2.setSalary(5500.1); System.out.println("员工二:" + e2); } public String getNumber() { return number; } public void setNumber(String number) { this.number = number; } public String getName() { return name; } public v