Java Getting Started concept personal understanding of access modifiers

Source: Internet
Author: User
Tags modifiers

Whether the corresponding modifiers for classes, methods, member variables, and local variables can be used

Modifier

Class

Member adapting

Construction method

Member variables

Local variables

Abstract (abstracted)

Static (statically)

Public (Common)

Protected (Protected)

Private (privately)

Synchronized (synchronous)

Native (local)

Transient (temporary)

Volatie (volatile)

Final (do not change)

class modifier

Public

can be accessed from other classes

Abstract

Cannot be instantiated, can contain abstract methods, abstract methods are not implemented, no specific functions, can only derive sub-classes

Final

Subclass can no longer be declared

constructor Modifier

Public

can be accessed from all classes

Protected

can only be accessed from its own class and its subclasses

Private

can only be accessed in this class

Domain / member Variable modifiers

Public

can be accessed from all classes

Protected

can only be accessed from this class and its subclasses

Private

It can only be accessed from this class

Static

Only one domain value exists for all instances of the class

Transient

is not part of an object's persistent state

Volatile

Can be modified by an asynchronous thread

Final

It must be given an initial value and cannot be modified

Local Variables modifier

Final

It must be given an initial value and cannot be modified

Method Modifiers

Public

It can be accessed from all classes

Protected

It can only be accessed from this class and its subclasses

Private

It can only be accessed from this class

Abstract

No method body, belongs to an abstract class

Final

Subclasses cannot overwrite it

Static

is bound to an instance of the class itself rather than the class

Native

This method is implemented by other programming languages

Asnchronized

Before a thread calls it, it must first add the

Java Getting Started concept personal understanding of access modifiers

Related Article

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.