java大题(8)

2019-08-17 13:52

this.r=r; }

public double size(){ return 3.14*r*r; } }

class Conference implements Shape{ private double peoples; public Conference(double p){ peoples=p; }

public double size(){ return peoples; } }

class 圆柱体 implements Shape{ private Circle c; private double h;

public 圆柱体(Circle c1,double h1){ c=c1;h=h1; }

public double size(){

return c.size()*h; } }

public class Java2 {

public static void main(String args[]){ Shape s[]=new Shape[4]; s[0]=new Line(22,56,41,57); s[1]=new Circle(47); s[2]=new Conference(247); s[3]=new 圆柱体(new Circle(20),4); for (int z=0;z

8(3)定义一个抽象类水果,包括getweight()方法。

abstract class Fruit{

abstract public double getWeight(); }

class Apple extends Fruit{ private double weight;

public Apple(double weight){ this.weight=weight; }

public double getWeight(){ return weight; } }

class Peach extends Fruit{ private double weight; public Peach(double weight){ this.weight=weight; }

public double getWeight(){ return weight; } }

class Orange extends Fruit{ private double weight; public Orange(double weight){ this.weight=weight; }

public double gerWeight(){

return weight; } @Override

public double getWeight() {

// TODO Auto-generated method stub return 0; } }

public class Java3 {

public static void main(String[]args){ Fruit s[]=new Fruit[3]; s[0]=new Apple(3); s[1]=new Peach(2); s[2]=new Orange(1); for(int k=0;k

System.out.println(s[k].getClass().getName()+\ } }

8(4)定义Startstop接口,含有start()和stop()两个方法。分别创建会议和汽车两个类实现Startstop接口。

interface StartStop{ void Start(); void Stop(); }

class Conference implements StartStop{ public void Start(){

System.out.println(\ }

public void Stop(){

System.out.println(\} }

class car implements StartStop{ public void Start(){

System.out.println(\ public void Stop(){

System.out.println(\ } }


java大题(8).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:提案建议关于把普通话作为公务用语用字规范性文件

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: