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