Abstract, the distinction between interface and abstract, the difference between native

Source: Internet
Author: User

Syntax differences:

Abstraction: Abstract Class--there is a construction method; Interface (interface) is not;

There are common member variables; interface not;

There is a non-abstract common method; interface is not;

The access type of the abstract method is public,protected; The abstract method of interface must be public abstract; The default is public abstract;

The type of a static member in an abstract method can be arbitrary; the type of the static member of the interface must be public static final decoration;

Application differences:

A class can inherit only one abstract class, and multiple interfaces may be implemented;

Abstract class: Mainly used for the reuse of code implementation;

Interface: It is mainly used for communication contract between modules, and plays a role in architecture design method.

The method of abstract can not be static. Because the abstract method is to be implemented by the quilt Class! Static is not related to sub-class!

Native: native;

Native method is the interface that Java calls non-Java code, the method has non-Java code implementation, when the native method is defined, it is not provided as the implementation body;

Abstract there is no realization body;

The native identifier can be in conjunction with the Java identifier, but not abstract;
Because the native has the realization body, abstract does not have the realization body
-----Example: When defining a native method, the implementation body is not provided (some like defining a Java Interface) because its implementation is implemented outside of the Java language
public class Ihavenatives
{
Native public void Native1 (int x);
Native static public long Native2 ();
Native synchronized private float Native3 (Object o);
native void Native4 (int[] ary) throws Exception;
}

 

Abstract, the distinction between interface and abstract, the difference between native

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.