Interface---Java

Source: Internet
Author: User

 PackageCom.test2; Public classTest { Public Static voidMain (string[] args) {//TODO auto-generated Method StubSystem.out.println (USB.A); //Create a computerComputer computer =Newcomputer (); //Create a CameraCamera camera1 =NewCamera (); //Create phonePhone phone1 =NewPhone ();        Computer.useusb (CAMERA1);    Computer.useusb (PHONE1); }}Interfaceusb{intA = 1; //two methods are declared in the interface//Start Working     Public voidstart (); //Stop Working     Public voidStop (); }//write the camera class and implement the USB interface//when a class implements an interface, it requires the class to implement all the interfaces of the class.classCameraImplementsusb{ Public voidstart () {System.out.println ("I'm a camera, I'm working."); }         Public voidStop () {System.out.println ("I'm the camera, stop working."); }}//Write Phone classclassPhoneImplementsusb{@Override Public voidstart () {//TODO auto-generated Method StubSystem.out.println ("I'm a cell phone, getting to work"); } @Override Public voidStop () {//TODO auto-generated Method StubSystem.out.println ("I'm a cell phone, stop working"); }    }classcomputer{//the interface also embodies polymorphic//Getting started with the USB interface     Public voidUSEUSB (USB usb) {Usb.start ();            Usb.stop (); }}

Interface---Java

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.