30天学会JAVA—练习题(2021韩顺平)——Day11

在这里插入图片描述

class Circle{
   
//	private final double PI = 3.14;//直接赋值
	private final double PI;
	private double radius;
	
	{
   
		PI = 3.14; // 代码块赋值
	}
	public Circle(double radius) {
   
		super();
		this.radius = radius;
//		PI = 3.14; //构造器赋值
	}
	
	public double s(){
   	
		return PI * radius * radius;		
	}
	
}

public class Test {
   	
	public static void main(String[] args) {
   
		System.out.println(new Circle(1.0).s());		
	}
}

在这里插入图片描述
在这里插入图片描述

4.代码
abstract class Employee{
   
	private String name;
	private String id;
	private int salary;
	
	public Employee(String name, String id, int salary) {
   
		super();
		this.name = name;
		this.id = id;
		this.salary = salary;
	}
	
	
	public String getName() {
   
		return name;
	}


	public void setName(String name) {
   
		this.name = name;
	}


	public String getId() {
   
		return id;
	}


	public void setId(String id) {
   
		this.id = id;
	}


	public int getSalary() {
   
		return salary;
	}


	public void setSalary(int salary) {
   
		this.salary = salary;
	}

	public abstract void work();//抽象方法不能有方法体
}

class Manager extends Employee{
   
	private int bonus;

	public Manager(String name, String id, int salary, int bonus) {
   
		super(name, id, salary);
		this.bonus = bonus;
	}

	public int getBonus() {
   
		return bonus;
	}

	public void setBonus(int bonus) {
   
		this.bonus = bonus;
	}

	@Override
	public void work() {
   
		System.out.println("普通员工:" + ",姓名: "+ getName() + ",id:" + getId() + ",薪水:"+ getSalary() + ",奖金:" + bonus +",工作中");		
	}		
}
class CommonEmployee extends Employee{
   

	public CommonEmployee(String name, String id, int salary) {
   
		super(name, id, salary);
	}

	@Override
	public void work() {
   
		System.out.println("普通员工:" + ",姓名: "+ getName() + ",id:" + getId() + ",薪水:"+ getSalary() +",工作中");
		
	}
}

public class Test {
   	
	public static void main(String[] args) {
   
	new CommonEmployee("ada", "123", 100).work();
	new Manager("jack", "001", 200, <
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值