The idea of Java oriented abstract programming

Source: Internet
Author: User

Sim.java

 Public Abstract class SIM {    publicabstractvoid  Setnumber (String n);      Public Abstract String Givenumber ();      Public Abstract String givecorpname ();}

Mobiletelephone.java

 Public class Mobiletelephone {   SIM card;     Public void Usesim (SIM card) {      this. card=card;   }      Public void showmess () {      System.out.println ("card used is:" +card.givecorpname () + "provided");      System.out.println ("mobile phone number is:" +Card.givenumber ());}   }

Simofchinamobile.java

 Public class extends SIM {    String number;      Public void Setnumber (String N) {        = n;    }      Public String Givenumber () {        return number ;    }       Public String Givecorpname () {        return "China Mobile";    }}

Simofchinaunicom.java

 Public class extends SIM {    String number;      Public void Setnumber (String N) {        = n;    }      Public String Givenumber () {        return number ;    }      Public String Givecorpname () {        return "China Unicom";    }}

Application.java

 Public class Application {   publicstaticvoid  main (String args[]) {      new  Mobiletelephone ();      Sim Sim=new  simofchinamobile ();      Sim.setnumber ("13887656432");      Telephone.usesim (SIM);      Telephone.showmess ();      Sim=new  simofchinaunicom ();      Sim.setnumber ("13097656437");      Telephone.usesim (SIM);      Telephone.showmess ();   }}

The idea of Java oriented abstract programming

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.