7. Interface, static method

Source: Internet
Author: User

 Public Interface A {    publicvoid  B ();     void c ();     void d ();}

What's wrong with the M extension connector?

 Public class Implements a{     void  B () {    }    publicvoid  C () {    }     publicstaticvoid  D () {    }}

1.bd problem, c no problem

2. Override the rule access modifier must be greater than the overridden method's access modifier (public>protected>default>private)

Abstract static methods cannot be defined in 3.java all of the member methods in Static,interface are abstract, and of course, static method statics cannot be defined.

4. All methods in an interface are abstract, and all member variables are public static final.

rules for overriding methods :

1. The parameter list must be exactly the same as the overridden method, otherwise it cannot be called overridden instead of overloaded.

2, the returned type must always be the same as the return type of the overridden method, otherwise it cannot be called overriding but overloaded.

3. The access modifier must be greater than the access modifier (public>protected>default>private) of the overridden method

4. The overriding method must not throw a new check exception or a more general type of check exception than the overridden method declares. For example:

A method of the parent class states that a check exception ioexception, in overriding this method is not able to throw exception, can only throw IOException subclass exception, can throw non-check exception.

Instead of overloading the rules:

1, must have a different list of parameters;

2, can have not scold return type, as long as the parameter list is different;

3, can have different access modifiers;

4, can throw different anomalies;

The difference between overrides and overloads is that:

Overriding polymorphism works, and calling overloaded methods can greatly reduce the amount of code input, and the same method name can have different functions or return values as long as it passes different parameters inside.

With good rewriting and overloading, you can design a clear and concise class that can be said to be overridden and overloaded in a way that is very unusual in the process of writing code.

7. Interface, static method

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.