static functions and static variables for Java

Source: Internet
Author: User

Static variables:

A static variable is like a member variable, which is characterized by a static front.

The normal variable will have multiple copies, it exists in each object, but there is only one copy of the static variable, it belongs to the class.

Methods for calling static variables:

1. Class name. Variable name

Customer.name = "South Central University"

2. Name of the object. Class Name

A1.name = "South Central University" the second more common

Normal variable static variable

Class name. Access can not be

The object name. Access can be

Static member functions:
Add static before the member function

1. A static member function can be a class name. member variable and object name. static member variable.

2. Static member functions can only invoke static member variables and cannot access ordinary variables.

The purpose of the invention of a static function: to manipulate static variables, to perform some content unrelated to a particular object

Static variable normal variable
Static functions can not be
Normal functions can be

——————————————————————————————————————————-

static functions and static variables for Java

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.