0
点赞
收藏
分享

微信扫一扫

java第九次作业

7dcac6528821 2022-04-14 阅读 68
javaeclipse

目录

1.多功能参数(方法的重载)

2.模拟上课场景(接口与实现)

3.儿子喜欢做的事(接口与实现 多实现)


1.多功能参数(方法的重载)

public class ZY1 {
static final  double PI=3.141592653589793;
	public static double add(double a,double b){
		return(a*b);
	}
	public static double add(double r){
		return(r*r*PI);
}
	
	public static void main(String[] args) {
		System.out.println(PI);
		System.out.println(add(4.0000001));
		System.out.println(add(3.0,4.0));
	}
}

2.模拟上课场景(接口与实现)

public class Teacher implements Move{//创建一个Teacher类实现接口Move
public String name;//定义姓名字段
public Teacher(String name)//对姓名字段进行初始化
this.name=name;
}
@Override
public void work()(//重写work)方法
System.out.println(name+":老师开始上课";
}
@Override
public void talk() (//重写talk()方法
System.out.println(name+":同学们好");
}
}
public class Student implements Move{//创建一个Student类实现接口Move
public String name;//定义姓名字段
}
public Student(String name){//对姓名字段进行初始化
this.name=name;
@Override
public void work(){//重写work()方法
System.out.println(name+":同学开始记笔记");
}
@Override
public void talk(0){// 重写talk0方法
System.out.println(name+":老师好");
}}

 

 

3.儿子喜欢做的事(接口与实现 多实现)

public interface IFather {
  void smoking();
  void goFishing();
}

public class We implements IFather,IMother {
 
	public void watchTV() {
	System.out.println("看电视");
		
	}
 
 
	public void cooking() {
		System.out.println("做饭");
		
	}
 
	
	public void smoking() {
		
		System.out.println("抽烟");
	}
 
 
	public void goFishing() {
	
		System.out.println("钓鱼");
	}
	public static void main(String[] args) {
	IFather father=new Me();
	IMother mother=new Me();
	System.out.println("儿子喜欢做的事有:");
	mother.watchTV();
	mother.cooking();
	father.smoking();
	father.goFishing();
 
	}
 
}

举报

相关推荐

0 条评论