Java第六次作业

package unit;
/**2021-4-15
 * 第一题
 * 任静
 */

public class Base {
    public Base(){
        System.out.println("Base");
    }
}
class Child extends Base{
    public Child(){
        System.out.println("Child");
    }
}
public class Sample {
    public static void main(String[] args) {
        Child c=new Child();
    }
}

Base
Child

进程已结束,退出代码为 0

package unit;
/**第二题
 * 2021-4-15
 * 任静
 */
public abstract class Animal {
    String color;
    String weight;
    int age;

}

package unit;

public class Bird extends Animal{
    Bird(String color, int age) {
        super.color = color;
        super.age = age;
    }
    public void printinfo() {
        System.out.println("我是一只" + color + "的鸟!");
        System.out.println("今年" + age + "岁了!");
    }
}


package unit;

public class Fish extends Animal{
    Fish(String weight, int age) {
        super.weight = weight;
        super.age = age;
    }
    public void printinfo() {

        System.out.println("我是一只" + weight + "重的鱼!");
        System.out.println("今年" + age + "岁了!");

    }

}


package unit;

public class Test {
    public static void main(String[] args) {
        Bird bird = new Bird("红色", 4);
        Fish fish = new Fish("5斤", 2);
        bird.printinfo();
        fish.printinfo();
    }

}


我是一只红色的鸟!
今年4岁了!
我是一只5斤重的鱼!
今年2岁了!

进程已结束,退出代码为 0

package unit2;
/**第三题
 * 2021-4-15
 * 任静
 */
public  abstract  class Phones {
    public abstract void call();
}


package unit2;

public class APhone extends Phones{
    public void call() {
        System.out.println("安卓手机打电话");
    }
}


package unit2;

public class IPhone extends Phones {
    public void call() {
        System.out.println("苹果手机打电话");
    }
}


package unit2;

public class WPhone  extends Phones{
    public void call() {
        System.out.println("WPhone手机打电话");
    }
}



package unit2;

public class TestCall {
    public static void main(String[] args) {
        Phones aPhone=new APhone();
        aPhone.call();
        Phones iPhone=new IPhone();
        iPhone.call();
        Phones wPhone=new WPhone();
        wPhone.call();
    }
}


安卓手机打电话
苹果手机打电话
WPhone手机打电话

进程已结束,退出代码为 0

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值