4、编写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方法这个是Java程序
时间: 2024-02-28 17:56:36 浏览: 94
解决Kotlin 类在实现多个接口,覆写多个接口中相同方法冲突的问题
InterfaceA.java:
```java
public interface InterfaceA {
void printCapitalLetter();
}
```
InterfaceB.java:
```java
public interface InterfaceB {
void printLowercaseLetter();
}
```
Print.java:
```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:
```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
```
阅读全文