Java-interface Exercises

Source: Internet
Author: User

Write 2 interfaces: Interfacea and interfaceb; There is a method Voidprintcapitalletter () in the interface interfacea, and there is a method void in the interface interfaceb Printlowercaseletter ();

After writing a class print implementation interface Interfacea and interfaceb, requires the Printcapitalletter () method to implement the function of the output capital English alphabet, printlowercaseletter () method to implement the function of outputting lowercase English alphabet. Write a main class e, create the Print object in the main method of the primary class e, and assign a value to the variable a of interfacea, and object A calls the Printcapitalletter method finally, the object in main class E's Main method is created and assigned to the variable B of interfaceb, and object B calls the Printlowercaseletter Method.

Interface 1

 package com.jiekoulianxi;  public Interface interfacea {        // abstract method    void    printcapitalletter ();}

Interface 2

 package com.jiekoulianxi;  public Interface interfaceb {            void  printlowercaseletter ();}

Implementation class;

 package com.jiekoulianxi;  public class Implements interfacea, interfaceb {    @Override    publicvoid  printlowercaseletter () {        System.out.println ("abcdefghijklmnopqistuvwxyz");    }    @Override    publicvoid  printcapitalletter () {        System.out.println ( "ascdefghijklmnopqrstuvwxyz");}    }

Test:

 package com.jiekoulianxi;  public class main {    publicstaticvoid  main (string[] Args) {        interfacea a= New Print ();        Interfaceb b=new  Print ();        B.printlowercaseletter ();        A.printcapitalletter ();            }}

Results:

Java-interface Exercises

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.