CPU Interface Exercises (only this program proves that a classmate is really poisonous!) Toxic!!! )

Source: Internet
Author: User


1 Creating an interface

 Package Lianxi;  Public Interface ICPU {    public  boolean neicun ();   Memory Interface     }

2 Create a class to connect to this interface

 Package Lianxi;  Public class Implements icpu {    @Override    publicboolean  Neicun () {                System.out.println (" CPU memory is too small ");         return true ;    }}

3 Creating a parent class

 Public classComputer {PrivateICPU CPU;  Publicicpu Getdiannao () {returnCPU; }     Public voidSetdiannao (Icpu CPU) { This. CPU =CPU; }     DoubleRongliang; BooleanCP () {Booleanrtn=true; if(rongliang>50) {System.out.println ("Installed a" +rongliang+ "CPU"); RTN=false; }Else if(cpu==NULL) {System.out.println ("CPU not Installed"); RTN=false; }Else{RTN= This. Cpu.neicun (); }return true; }    }

4 Creating subclass Calls

 Package Lianxi;  Public class Ceshi {    publicstaticvoid  main (string[] args) {        // TODO Auto-generated method stubs        Computer cop=New  computer ();        Cop.rongliang=34;
System.out.println ("When the capacity is" +cop.rongliang+ "); Cop.setdiannao (new Cpuceshi ()); Cop. CP ();} }

 Package Lianxi;  Public class Ceshi {    publicstaticvoid  main (string[] args) {        // TODO Auto-generated method stubs        Computer cop=New  computer ();        Cop.rongliang=70;        System.out.println ("When the capacity is" +cop.rongliang+ ");        Cop.setdiannao (new  Cpuceshi ());        Cop. CP ();}            }

CPU Interface Exercise (only this program proves that a classmate is really poisonous!) Toxic!!! )

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.