The alphabet of Java object-oriented exercises polymorphism

Source: Internet
Author: User

. Write 2 interfaces:interfacea and interfaceb; in interface interfacea there's a way. void

Printcapitalletter (); there is a method in interface interfaceb void printlowercaseletter () ; then

Write a class print Implementation interface Interfacea and interfaceb, require print Capitalletter () method

Implements the output uppercase English alphabet function, theprintlowercaseletter () method implements the output lowercase English

The function of the alphabet. Write a main class e, create the Print object in the main method of the primary class e , and assign

The value given to the interfacea variable a, Object a calls print Capitalletter method; Finally again in the main class E

The main method creates the Print object and assigns a value to the variable bof the interfaceb Object b call

Printlowercaseletter method.

Interfacea interface package alphabet; public interface Interfacea {void Printcapitalletter ();}

  

Intfaceb interface package alphabet; public interface Interfaceb {void Printlowercaseletter ();}

  

Print class package alphabet; public class Print implements Interfacea, Interfaceb {@Overridepublic void Printcapitalletter () { System.out.println ("A,b,c,d,e,f,g,h,i,g,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z");} @Overridepublic void Printlowercaseletter () {System.out.println ("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x, Y,z ");}}

  

Main class Epackage alphabet; public class E {public static void main (string[] args) {interfacea a=new Print (); A.printcapitalletter (); Interfaceb b=new Print (); B.printlowercaseletter ();}}

  

Run results

The alphabet of Java object-oriented exercises polymorphism

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.