Java Reflection Mechanism Series (ii) example

Source: Internet
Author: User

Here I take the customer to buy a camera for example to illustrate the application of Java reflection mechanism. The classes and interfaces involved in the example are:

Camera interface: Defines the Takephoto () method.

Camera01 class: A type of camera that implements the camera interface.

CAMERA02 class: Another type of camera that implements the camera interface.

Seller class: Selling cameras.

Customer class: Buy a camera, there is a main method.

All classes are in a COM package.

The procedure is as follows:

public interface Camera {
  //声明照相机必须可以拍照
public void takePhoto();
}
public class Camera01 implements Camera {
private final int prefixs =300;//300万象素
private final double optionZoom=3.5; //3.5倍变焦
public void takePhoto() {
 System.out.println("Camera01 has taken a photo");
}
}

Similar to having

public class Camera02 implements Camera {
private final int prefixs =400;
private final double optionZoom=5;
public void takePhoto() {
 System.out.println("Camera02 has taken a photo");
}
}

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.