java基础—接口1

 1 package jiekou;
 2 
 3 public interface InterfaceA {
 4     /*
 5      * InterfaceA和InterfaceB;
 6      * 在接口InterfaceA中有个方法void printCapitalLetter();
 7      * 在接口InterfaceB中有个方法void printLowercaseLetter();
 8      */
 9     void printCapitalLetter();
10 }
1 package jiekou;
2 
3 public interface InterfaceB {
4     /*
5      * 在接口InterfaceB中有个方法void printLowercaseLetter();
6      */
7     void printLowercaseLetter();
8 }
 1 package jiekou;
 2 
 3 public class Print implements InterfaceA, InterfaceB {
 4     /*
 5      * 然 后写一个类Print实现接口InterfaceA和InterfaceB,要求printCapitalLetter()方法
 6      * 实现输出大写英文字母表的功能,printLowercaseLetter()方法实现输出小写英文 字母表的功能。
 7      */
 8     @Override
 9     public void printLowercaseLetter() {
10         System.out.println("abcdefghijklmnopqrstuvwxyz");
11 
12     }
13 
14     @Override
15     public void printCapitalLetter() {
16         System.out.println("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
17 
18     }
19 
20 }
 1 package jiekou;
 2 
 3 public class E {
 4     
 5 
 6     public static void main(String[] args) {
 7         /*
 8          * 写一个主类E,在主类E的main方法中创建Print的对象并赋
 9          * 值给InterfaceA的变量a,对象a调用printCapitalLetter方法;
10          * 最后再在主类E的main方法中创建Print的对象并赋值给InterfaceB的变量b,
11          * 对象b调用 printLowercaseLetter方法。
12          */
13         Print a=new Print();
14         a.printCapitalLetter();
15         Print b=new Print();
16         b.printLowercaseLetter();
17                 
18         
19 
20     }
21 
22 }

原文地址:https://www.cnblogs.com/yg6405816/p/5534428.html