接口练习1

编写2个接口:InterfaceA和InterfaceB;在接口InterfaceA中有个方法void

printCapitalLetter();在接口InterfaceB中有个方法void printLowercaseLetter();然

后写一个类Print实现接口InterfaceA和InterfaceB,要求printCapitalLetter()方法

实现输出大写英文字母表的功能,printLowercaseLetter()方法实现输出小写英文

字母表的功能。再写一个主类E,在主类E的main方法中创建Print的对象并赋

值给InterfaceA的变量a,对象a调用printCapitalLetter方法;最后再在主类E

的main方法中创建Print的对象并赋值给InterfaceB的变量b,对象b调用

printLowercaseLetter方法。

package homework;

public interface InterfaceA {
    
    
    void printCapitalLetter();
    
}
package homework;

public interface InterfaceB {
    void printLowercaseLetter();
    
    

}
package homework;

public class Print implements InterfaceA, InterfaceB {

    @Override
    public void printLowercaseLetter() {
        // TODO 自动生成的方法存根

        //小写
        for(char i='a';i<='z';i++)
        {
            System.out.print(i+" ");
        }
        
        
    }

    @Override
    public void printCapitalLetter() {
        // TODO 自动生成的方法存根

        //大写
        for(char i='A';i<='Z';i++)
        {
            System.out.print(i+" ");
        }
        
        
    }

}
package homework;

public class TestPrint {
    
    
    
    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        
        InterfaceA a=new Print();
        a.printCapitalLetter();

        System.out.println();
        
        InterfaceB b=new Print();
        b.printLowercaseLetter();
        
        
        
        
        
        
    }

    
}

运行结果:

原文地址:https://www.cnblogs.com/miss123/p/5523529.html