Definition and use of JAVA variables "the specificity of reference variables"

Source: Internet
Author: User

There are 2 main types of main variables in Java:

Basic data Types : Byte, short, int, long and float, double, or master data type

And

Reference data Types : Arrays, classes, interfaces; Reference variables save the reference only, not the object itself ;

Reference passing is the use of a memory, a piece of memory can be used by many people;

because the " array is an object " in Java, regardless of whether it holds the primary data type or the object reference, but you can declare an array of values that can be loaded into the main data type.

An array object can have elements of the main data type, but the array itself is definitely not the primary data type???????

So, The use of arrays in Java must be "declared" and "allocated memory";

Each element in the array is a variable;

Routine 1: An array of master data

Int[] nums;//declaration of an array variable

Nums = new int[7];//allocates memory, creates an array of size 7//nums[0] is a variable of type int

NUMS[1] is a variable of type int

NUMS[2] is a variable of type int

Routine 2: An array of objects

Dog [] pets; Declaring a dog array

Pets = new Dog[7]; Allocates memory, creates a dog array of size 7, and assigns a variable pets to the dog[] type previously declared;

Pets[0] = new Dog (); Only reference variables with dog are in the array.

PETS[1] = new Dog (); Only reference variables with dog are in the array.

Definition and use of JAVA variables "the specificity of reference 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.