Java class modifier

Source: Internet
Author: User
Tags modifier modifiers

The modifiers for Java are: permission modifiers: public, protected, default, private
Modifiers: abstract, static, final

Public uses objects: broadest, class, interface, variable, method
Protected using objects: variables, methodsNote: Classes cannot be decorated (external classes)
Default uses objects: classes, interfaces, variables, methods. (That is, by default, nothing is written)
Private Use objects: variables, methodsNote: Classes cannot be decorated (external classes)

Abstract using objects: classes, interfaces, methods
Static uses objects: classes, variables, methods, initialization functions (Note: Only the inner class can be decorated when the class is decorated)
Final use objects: classes, variables, methods

Transient: Tells the compiler that this variable does not need to persist when the class object is serialized
Volatile: Indicates that there may be multiple threads modifying this variable, requiring compiler optimizations to ensure that modifications to this variable are handled correctly

Native: The method defined with this modifier is not implemented in the class, and in most cases the implementation of the method is written in C and C + +.
Synchronized: Modification method, multithreading support


Class and inner class, are their access controls the same?
The outer class is relative to the inner class, and the inner class is the class defined within the class.

The modifiers for the outer class are:
Default (default, not written): The class definition is preceded by no modifiers, indicating that the same package is visible.
Public: When a class is decorated, it indicates that the class can be visible to all classes in the project
Abstract: Represents an abstraction class
Final: Indicates that the class cannot be inherited
SCRICTPF: (Java keyword) when you use the STRICTFP keyword on a class or interface, all the code in that class, including the initial setpoint and code in the nested type, is evaluated Strictly. Strict constraints mean that the results of all expressions must be the result of an IEEE 754 algorithm's expected operand, expressed in single-precision and double-precision formats

The inner class is divided into: Member inner class, local inner class, Static inner class, Anonymous inner class
member Inner class: exists as a member of an external class, and is parallel to the properties, methods of the outer class
Local inner class: A class defined inside a method body of an outer class
Static inner class: inner class with static decoration
Anonymous inner class: is an inner class without a name

The member interior class modifiers are:
Public
Protected
Private:private cannot decorate external classes,
Abstract
Final
Static: Can be used as a normal class without first instantiating an external class. (after he modifies it, it becomes a static inner class.)
STRICTFP: (Java keyword) Strict float point(exact floating point). (Can be decorated class, interface, method)

Local inner class:
A local inner class is a class defined in a method within a class.
Local classes have an advantage, that is, to be completely hidden from the outside world. Even other methods in the same class cannot access it.
A local class can access the outer class that contains it, and it can also access local variables.

A local class cannot be declared with public or private access specifiers, and his scope is limited to this method,


Access rights and Inheritance:
The access modifier here refers to: Modifies member variables and methods. In two cases:
1. Subclasses are in the same package as the parent class:
Only private-modified variables and methods cannot be accessed at this time.
2. A subclass is not in the same package as the parent class:
Neither private nor default can be accessed at this time, and protected and public may


Interface modifiers:
Public: All Packages visible
Default: (default) visible in the same package
STRICTFP: (Java keyword) Strict float point(exact floating point).

Interface variables always need to be defined as: public static final type name, but can not write so complex, the default is public static final

The method of an interface can only be decorated with public, abstract.

Java class modifier

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.