Modifiers for the Java language

Source: Internet
Author: User
Tags abstract final modifier modifiers

Available modifiers for classes, methods, member variables, and local variables

Modifiers Class Member Methods Construction method Member variable Local variables
Abstract Y Y _ _ _
Static _ Y _ Y _
Public Y Y Y Y _
Protected _ Y Y Y _
Private _ Y Y Y _
Synchronized _ Y _ _ _
Native _ Y _ _ _
Transient _ _ _ Y _
Volatile _ _ _ Y _
Final Y Y _ Y Y

1, access control modifier:

The Java language uses access control modifiers to control the access rights of classes and classes ' methods and variables, exposing only the interface to the consumer, but hiding the implementation details.

Public level: To be publicly decorated, externally

Protected level: Protected decorated, exposing to subclasses and classes in the same package

Default level: No access control modifiers are exposed to classes in the same package

Private level: Decorated with private, only the class itself can be accessed, not public

The top-level class has only the default or public level, so it cannot be decorated with private and protected.

2, abstract modifier:

Used to modify class and member methods, abstract classes cannot be instantiated, and abstract methods do not provide specific implementations.

Abstract classes can have no abstract methods, but classes that contain abstract methods must be defined as abstract classes

If the subclass does not implement all of the abstract methods in the parent class, then the subclass must also be defined as an abstract class

No abstract construction method, no abstract static method

Abstract classes can have non-abstract construction methods that may be invoked when instances of subclasses are created

Abstract classes and abstract methods cannot be decorated with the final modifier (why?) )

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.