Java (8) control logic modifier

Source: Internet
Author: User

Package catalog concept, the box packages are placed at the front of the source file, the pack statement can only have one, multi-layer "." Segmentation

How to use the package, the same packet class direct reference, different packages import package name. *; Import package name. class name import to be referenced after the

Static Introduction:

Introduces static member variables and static methods in the package, static

Import static package name. aaa.*;

Import static package name. AAA. Method name;

Class access level: Public (cross-package), default access level (in-package), protect,private,abstract,final (final modifier: once initialized, it can no longer be modified.) )

Member variable for final decorated object type: must be initialized. is not initialized by default. The value of the modified member variable cannot be changed (the base type value cannot be changed; Reference type references cannot be changed, but the member variables of the referencing object can be changed). The constructor method can initialize a member variable.

Final modifier local variable: Can not be initialized.

Final modification method: The final decorated method can be inherited by the quilt class, but cannot be overridden. Some special data for the parent class is protected.

Final decorated base type: The value of the base type cannot be changed

Encapsulation: A member variable and method defined within a class that restricts the visibility of its member variables and methods so that they cannot be accessed by the outside world. So the package shows the interface and hides the details.

static modifier statics:

There can be only one copy in memory.

Static variable: Only one copy, which belongs to the class, does not belong to the object. Static member variables are shared by all objects in the class.

Constructor: Executes every time the creation occurs

Access static member variables: class names. static member variables; static member variables; this cannot be used;

Static constant: Static final does not have a default value and must be initialized

Package Demo;import static Java.lang.system.out;public class Test {public static void main (string[] args) {//TODO Auto-ge Nerated method Stubout.println ("Printing data by static Introduction");}}

  

Package Demo;import static Java.lang.system.out;public class Test {final int i;public test (int i) {this.i = i;} public static void Main (string[] args) {//TODO auto-generated method Stubout.println ("to introduce printing data by static"); Test t = new Test (155) ; int n = t.i;out.println (n);}}
Package demo;import static Java.lang.system.out;class bike{string color = "Yellow";p ublic final void Getmes () {out.println (" Parent class member Variable color: "+ Color";}} public class Test extends bike{final int i; String color = "Green";p ublic test (int i) {this.i = i;} public static void Main (string[] args) {//TODO auto-generated method Stubout.println ("to introduce printing data by static"); Test t = new Test (155) ; int n = t.i;out.println (n); T.getmes ();}}

  

  

Modifiers in Java are categorized as class modifiers, field modifiers, method modifiers. According to the function of different, mainly divided into the following several.

1, the access modifier public,protected,default,private, these four levels of modifiers can be used to decorate classes, methods and fields.
Package my husband class inside class

Public Yes Yes Yes Yes

Protected no Yes Yes Yes

Default No No Yes Yes

Private No no No Yes

2. Final modifier final means immutable, he can modify classes, fields, methods. The class cannot be extended (extends) after the class is decorated, that is, it cannot be inherited. The value of the field cannot be changed after the decorated field, so if there is a final decorated field, the field should be manually initialized. The method cannot be changed after modifying the method, that is, rewriting.

3, abstract modifier abstraction is the meaning, used to modify classes and methods, after the class, the class is abstract class, can not be instantiated, must be extended. After the method is modified, the method must be overridden by a quilt class (override) for the abstract method.

4, static modifier static is used to decorate the inner class, method, field. The cosmetic inner class shows that the inner class belongs to an external class and does not belong to an instance of an external class. A modifier field indicates that the field belongs to a class and does not belong to a class instance. The modification method indicates that the method belongs to a class and not to a class instance

Java (8) control logic 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.