Older Dick Silk Self-study note--java 0 basics to rookie--015

Source: Internet
Author: User

A member variable is compared to a local variable, a base type is a method argument with a reference type, and an anonymous object

1. Comparison of member variables and local variables

The position in the class is different: The member variable, outside the method.

Local variables, within the method.

The locations in memory are different: member variables, stack memory.

Local variables, heap memory.

The life cycle is different: member variables exist as the object exists.

Local variables, which exist as the method exists.

Initialization values are different: member variables, with default initial values.

Local variable, there is no default initial value.

Note: When the member variable and local variable have the same name, the nearest rule is executed.

1 class fin{2     int n=1; 3      Public Static void Main (string[] args) {4         int n=2; 5         SYSTEM.OUT.PRINTLN (n);  // Output 2 6     }7 }

2, basic types and reference types to do method parameters

Base type: The value of the formal parameter is changed without affecting the value of the actual parameter, such as an int type parameter.

Reference type: The value of the formal parameter changes, affecting the actual parameters of the value, such as: class type parameters.

3. Anonymous objects

Can only be called once, such as: "New Fin (). method ();", "Method (New Stu ());".

Older Dick Silk Self-study note--java 0 basics to rookie--015

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.