zoukankan      html  css  js  c++  java
  • 接口练习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();
            
            
            
            
            
            
        }
    
        
    }

    运行结果:

  • 相关阅读:
    Python3-元组
    Python3-列表
    Python3-字符串
    Python3-for循环机制
    Python3-初识
    优先队列——priority queue
    单调队列 —— 滑动窗口
    SDNU_ACM_ICPC_2021_Winter_Practice_7th [个人赛]
    博弈论入门(论和威佐夫、巴什、尼姆打牌被吊打是什么感受(╥﹏╥)
    字符串最大最小表示法
  • 原文地址:https://www.cnblogs.com/miss123/p/5523529.html
Copyright © 2011-2022 走看看