Java interface implementation

Source: Internet
Author: User

In Java, if a constant conflicts with a method in an interface. 1. If a constant conflict exists, a fully qualified name can be used in the Implementation interface (interface name. Constant name explicitly specifies the interface to which the constant belongs

If there is a method conflict, you only need to implement one method.

Public class HH {public static void main (string [] ARGs) {circle = new circle (7); float area = circle. getarea (); system. out. println ("Area of the circle:" + area); float girth = circle. getgirth (); system. out. println ("circle circumference:" + girth); circle. draw () ;}} class circle implements calculate, shape {// declare a variable to indicate the radius private float radius; public circle (float R) {radius = r ;} public float getarea () {float area = calculate. pI * radius * radi US; return area;} public float getgirth () {float circugirth = 2 * shape. pI * radius; return circugirth;} public void draw () {system. out. println ("draw a circle here! ") ;}} Interface calculate {float Pi = 3.14f; float getarea (); float getgirth () ;}interface shape {float Pi = 3.14159f; float getarea (); void draw ();}

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.