0
点赞
收藏
分享

微信扫一扫

80题通关Java基础:第61题


目录

  • ​​第61题 代码填空, Colors接口基本使用操作(10分)​​
  • ​​🍋题目描述​​
  • ​​🍋源代码​​

第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;
}
}

80题通关Java基础:第61题_抽象方法


举报

相关推荐

0 条评论