"Head first Java"--Recognize variables

Source: Internet
Author: User

References to Objects

Book B = new book ();

Book C = new book ();

Book d = C; //Declares a new book reference variable, but does not create a new book object and assigns the value of variable C to the variable d. This means "copy the byte combination of C to variable D", where C and D are referenced to the same object.

c = b; //b and C both refer to the same object.

An array is like a cup holder

int [] nums; //declare an int array variable. Array variable is the remote control of an array object

nums = new int [7]; //Create an array of size 7 and assign it to a variable previously declared as int[] nums

nums [0] = 6;......nums[6] = 1; //assigns to each element in the array.

Create a dog array

Dog [] pets; //Declare a dog array variable

Pets = new Dog[7]; //Create a dog array of size 7 and assign values to the dog[] type variable pets declared earlier.

Pets [0] = new Dog (); //Create new Object dog objects and assign them to the elements of the array

Pets [1] = new Dog ();

How do I access the dog in the dog array?

Only the array index (position) is required to manipulate specific objects

Dog [] mydogs = new dog [3];

mydogs [0] = new Dog ();

mydogs [0]. Name = "Fido";

mydogs [0]. Bark ();

"Head first Java"--Recognize 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.