Beginner summary--------java modifier and modifier keyword (also called cosmetic keyword)

Source: Internet
Author: User

There are classes in Java, there are member variables, there are member methods, there are local variables. What can they do with each other?

Classes that are currently being learned have common classes and inner classes.

I. Modifying a general class:

1.public only one class in each file can be modified by public, indicating that it can be accessed by any object

2.abstract abstract class, can not be instantiated, there may be an abstract method. The effect of no abstract method is to avoid instantiating the class

3.final final class, indicating that it cannot be inherited

4.abstract abstract class, cannot be instantiated, is the new object

Inner class: Has member inner class, local inner class, anonymous inner class, Static inner class (skip first)

Two. Modifier variables: Variables have member variables and local variables

Modify member Variables:

1.public can be accessed by any object

2.private can only be used by its own class

3.protected In addition to its own class, the same package, sub-class other than can not be used, quilt class overrides

4.final represents the constant amount of the member variable, but the initialization cannot be changed;

5.static static member variables, which are loaded when the class is loaded, are not dependent on instantiation, and can be used with the class name. Variable name. And the variable has only one copy in the class, which means that all objects are used together. (Cannot modify local variables)

To modify a local variable:

1.final is a final modification of the constant, one but initialization, the value cannot be changed

 

Three: Modification method

1.public Ibid.

2.protected Ibid.

3.private Ibid.

4.static static method, loaded when the class loads. You do not need to create an object to use the class name. Method Name

(cannot be modified together with abstract method, class load to load, and abstract method is an abstraction method, meaningless)

The 5.final method can be inherited by the quilt class, but cannot be overridden

(cannot be combined with abstract method, final cannot be overridden, and abstract requires override)

6.abstract the method has no method body and its class must be defined as an abstract class

(Not with final co-decoration method, same as 5)

IV: Inner class

The member inner class, as the name implies, is similar to a member and can be modified by modifying the member variable. Unlike methods, abstract and static can collectively modify inner classes

Local inner class, similarly, can modify the local variable can modify him, final

Anonymous inner class, there is no definition of class.

A static inner class that modifies a member's inner class to modify it.

Beginner, welcome.

Beginner Summary--------java modifier and cosmetic keyword (also called cosmetic keyword)

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.