80题通关Java基础:第61题

第61题 代码填空, Colors接口基本使用操作(10分)

🍋题目描述

此题的上机步骤是:

  1. 建立一个Java项目,名称可以按题号取名;
  2. 建立一个类, 类的名称为Main。这一点非常重要;
  3. 填代码;
  4. 提交代码,注意题号要一致。

下列Java应用程序是接口的定义、继承和基本使用操作。
请按程序实现要求,将下面程序的【代码】替换为Java程序代码。

文件Main.java
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Baseclass b=new 【代码1】();
int n=b.getColorValue();
System.out.println(“n=”+n);
}
}
//定义接口BaseColors
interface BaseColors {
//这里都是静态公共常量
int RED = 1, GREEN = 2, BLUE = 4;
//这是一个抽象的公共方法
int getColorValue(int color);
}
//接口RainbowColors继承了BaseColors
interface RainbowColors
extends 【代码2】 {
//新增加了4个成员常量
int YELLOW = 3, ORANGE = 5,
INDIGO = 6, VIOLET =7;
//还自动继承了父接口的3个成员常量和1个抽象方法

}
//接口PrintColors继承了BaseColors
interface PrintColors
extends BaseColors {
//增加3个成员常量
int YELLOW = 8, CYAN = 16, MAGENTA = 32;
//覆盖了父接口的成员方法,仍然是抽象的
int getColorValue(int color);
//还可以重载,和其它方法名相同,但参数有差异
int 【代码3】();
}
//接口PrintColors继承了BaseColors
interface LotsOfColors extends RainbowColors, PrintColors {
//这是多重继承,增加3个成员常量
int FUCHSIA = 17, VERMILION = 43, CHARTREUSE = RED+90;
}

class Baseclass 【代码4】 LotsOfColors {
@Override
public int getColorValue() {
// TODO Auto-generated method stub
return 0;
}
@Override
public int 【代码5】(int color) {
// TODO Auto-generated method stub
return 0;
}
}

🍋源代码

public class Main {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Baseclass b=new Baseclass();
        int n=b.getColorValue();
        System.out.println("n="+n);
    }
}
//定义接口BaseColors
interface BaseColors {
      //这里都是静态公共常量
      int RED = 1, GREEN = 2, BLUE = 4;   
      //这是一个抽象的公共方法
      int getColorValue(int color);
}
//接口RainbowColors继承了BaseColors
interface RainbowColors
extends BaseColors {
    //新增加了4个成员常量
      int YELLOW = 3, ORANGE = 5,
              INDIGO = 6, VIOLET =7;
//还自动继承了父接口的3个成员常量和1个抽象方法     
     
}
//接口PrintColors继承了BaseColors
interface PrintColors
extends BaseColors {
    //增加3个成员常量
      int  YELLOW = 8, CYAN = 16, MAGENTA = 32;
    //覆盖了父接口的成员方法,仍然是抽象的
      int  getColorValue(int color);
    //还可以重载,和其它方法名相同,但参数有差异
      int getColorValue();
}
//接口PrintColors继承了BaseColors
interface LotsOfColors extends RainbowColors, PrintColors {
      //这是多重继承,增加3个成员常量
       int FUCHSIA = 17, VERMILION = 43, CHARTREUSE = RED+90;
    }

class Baseclass implements LotsOfColors {
@Override
public int getColorValue() {
// TODO Auto-generated method stub
return 0;
}
@Override
public int getColorValue(int color) {
// TODO Auto-generated method stub
return 0;
}
}

在这里插入图片描述


如果这篇文章对你帮助很大,麻烦帮忙,点下友情链接: 鱼儿项目网(直接点这里),进去之后切换几个页面,停留几十秒。感激不尽。本站采集全网自媒体,网赚类,电商营销课程。里面有一些免费项目大家也可以看看

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

m明月Java3

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值