java定义类的方法

题目

package lesson03;

public class demo08 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Employee emp = new Employee("贾树行",006,1222);
		//调用
		emp.say();
		

	}

}
//定义员工类
class Employee{
	private String name;
	private int id;
	private double salary;
	//有参
	public Employee(String name, int id, double salary) {
		this.name = name;
		this.id = id;
		this.salary = salary;
	}
	//空参
	public Employee() {
	
	}
	//get,set方法

	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public double getSalary() {
		return salary;
	}
	public void setSalary(double salary) {
		this.salary = salary;
	}
	public void say() {
		System.out.println("姓名:"+name+"编号:"+id+"工资:"+salary);
	}
	
	
}









发布了44 篇原创文章 · 获赞 8 · 访问量 3750

猜你喜欢

转载自blog.csdn.net/weixin_43669384/article/details/104273564
今日推荐