编写2个接口:InterfaceA和InterfaceB;在接口InterfaceA中有个方法voidprintCapitalLetter();在接口InterfaceB中有个方法void printLowercaseLetter();然后写一个类Print实现接InterfaceA和InterfaceB,要求printCapitalLetter()方法实现输出大写英文字母表的功能,printLowercaseLetter()方法实现输出小写英文字母表的功能。再写一个主类E,在主类E的main方法中创建Print的对象并赋值给InterfaceA的变量a,对象a调用printCapitalLetter方法;最后再在主类E的main方法中创建Print的对象并赋值给InterfaceB的变量b,对象b调用printLowercaseLetter方法
时间: 2024-02-28 20:56:03 浏览: 36
接口 InterfaceA:
```java
public interface InterfaceA {
void printCapitalLetter();
}
```
接口 InterfaceB:
```java
public interface InterfaceB {
void printLowercaseLetter();
}
```
Print 类实现了 InterfaceA 和 InterfaceB 接口:
```java
public class Print implements InterfaceA, InterfaceB {
@Override
public void printCapitalLetter() {
for (char c = 'A'; c <= 'Z'; c++) {
System.out.print(c + " ");
}
System.out.println();
}
@Override
public void printLowercaseLetter() {
for (char c = 'a'; c <= 'z'; c++) {
System.out.print(c + " ");
}
System.out.println();
}
}
```
主类 E:
```java
public class E {
public static void main(String[] args) {
InterfaceA a = new Print();
a.printCapitalLetter();
InterfaceB b = new Print();
b.printLowercaseLetter();
}
}
```
输出:
```
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
a b c d e f g h i j k l m n o p q r s t u v w x y z
```
阅读全文