java-member variables and local variables

Source: Internet
Author: User

java-member variables and local variables
a difference between the two
1, scope of action:
Member variables act on the entire class
A local variable acts on a function or statement.
, 2, in-memory location
Member variable: In heap memory, because the object exists, it exists in memory
Local variables: in-stack memory
3, Initialize value
Member variables are initialized to 0 and can be used directly
Local variables are not initialized by default and cannot be used.
two building code blocks
Function: Initialize an object
The object runs as soon as it is established and takes precedence over the constructor execution

differences from constructors:
Constructing code blocks is a uniform initialization for all objects.
The constructor is initialized to the corresponding object.
The initialization content of different object commonalities is defined in the Construction code block

{    System.out.println("Hello World!");}

Add braces to a class, call functions inside, and so on.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

java-member variables and local variables

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.