Java-接口练习
编写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方法。
接口1
package com.jiekoulianxi;public interface InterfaceA {//抽象方法voidprintCapitalLetter(); }
接口2
package com.jiekoulianxi;public interface InterfaceB {void printLowercaseLetter();}
实现类;
package com.jiekoulianxi;public class Print implements InterfaceA, InterfaceB {@Overridepublic void printLowercaseLetter() {System.out.println("abcdefghijklmnopqistuvwxyz");}@Overridepublic void printCapitalLetter() {System.out.println("ASCDEFGHIJKLMNOPQRSTUVWXYZ");}}
测试:
package com.jiekoulianxi;public class Main {public static void main(String[] args) {InterfaceA a=new Print();InterfaceB b=new Print();b.printLowercaseLetter();a.printCapitalLetter();}}