java编程定义狗_帮我用JAVA做下下面2题谢谢1.按要求编写一个Java应用程序:(1)定义一个接口CanCry,描述会吼叫的方法publicvoidcry().(2)分别定义狗类(Dog)和猫类...

//第一题 文件1CanCry.java

public interface CanCry {

\x09public void cry();

}

//第一题 文件2 Cat.java

public class Cat implements CanCry {

\x09public void cry() {

\x09\x09System.out.println("猫,叫声是喵喵喵");

\x09}

}

//第一题 文件3 Dog.java

public class Dog implements CanCry {

\x09public void cry() {

\x09\x09System.out.println("狗,叫声是汪汪汪");

\x09}

}

//第一题 文件4 G.java

public class G {

\x09void makeCry(CanCry c){

\x09\x09c.cry();

\x09}

\x09public static void main(String[] args) {

\x09\x09Cat cat = new Cat();

\x09\x09Dog dog = new Dog();

\x09\x09G g = new G();

\x09\x09g.makeCry(cat);

\x09\x09g.makeCry(dog);

\x09}

}

//第二题 R.java

public class R {

\x09public int[] abc(int len){

\x09\x09int[] result = new int[len];

\x09\x09for(int i=0;i

\x09\x09\x09result[i] = (int)(Math.random()*(11)+10);

\x09\x09}

\x09\x09return result;

\x09}

\x09public void printA(int[] info){

\x09\x09int len = info.length;

\x09\x09for(int i=0;i

\x09\x09\x09System.out.println(info[i]);

\x09\x09}

\x09}

\x09public static void main(String[] args) {

\x09\x09R r = new R();

\x09\x09int[] info = r.abc(10);

\x09\x09r.printA(info);

\x09}

}

作业帮用户

2016-12-02

举报

6c0a0adef10d1043fa4f41a7897345ed.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值