java_day04 Java Basics

Source: Internet
Author: User

1. Keyword static
-Used to decorate the members of a class (Properties/Methods/inner classes)
-If access permission is allowed, static decorated members can pass the class name. method to access, that is, the object is created in the case of access, you can also pass through the object. The way to access
-Static decorated members are called Class members and are shared for many instances of the class
-The static property of the class can only be accessed inside the static method, not the non-static property of the class, and the non-static method can access the static member
-Because the static method cannot be accessed without an instance, the static method cannot have this and super inside
-Static initialization: Statically modifies a block of code that executes when the class is loaded and is executed only once (function: Initialize as a static property)


2. Single-state design mode: It is to take certain methods to ensure that only one object instance can exist for a class in the whole software system.
-It is not possible to create instances outside of the class by means of the new constructor, so the constructor is hidden, that is, the constructor is privatized.
Private single () {}
-Because an instance of a class cannot be created outside of the class, it can only be created inside the class
Single Instance = new single ();
-To use the instance directly outside of the class, use the static modifier
Static Single Instance = new single ();
-You cannot modify this property outside of the class, you can only privatize the property, and the colleague provides a public get method to use
private static Single Instance = new single ();
public static single getinstance () {
return instance;
}


3. Final keyword: classes, properties, and methods can be decorated
-Must be initialized in life or in a non-static block of code, or initialized in a constructor
-Final decorated property is constant, property value cannot be modified
-final modified method, cannot be modified cannot be overridden
-Final modified class, cannot be extended, cannot be inherited


4. Abstract keyword, for modifying classes and methods
-the modified method has no method body, only the declaration of the method (abstract method)
-Modified classes (abstract classes) cannot be instantiated
-Classes with abstract methods must be abstract classes, otherwise
-Cannot modify private method/constructor/static method


java_day04 Java Basics

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.