1 Chicken farm 2 farm new Chicken5 Describe the memory cell

 1   Chicken farm[]; 2   farm = new Chicken[5];  Describe the memory cell farm and its contents after executing line 1 Describe the memory cell farm and its contents after executing line 2 Describe any other interesting memory cells after executing line 2 

Solution

Please follow the data and description :

CODE :

The given code is :

1   Chicken farm[];
2   farm = new Chicken[5];

a) Describe the memory cell farm and its contents after executing line 1 :

Here after the execution of the first line the object named farm of array type of the class Chicken has been declared but that it is to be noted that the vraible has not been initialised so could not be used to run the code and use the varaible. So this throws a compile error for the data to be initialised.

b) Describe the memory cell farm and its contents after executing line 2 :

So now after the second line execution the array type object is initialised with a size of the 5. This conveys that the farm object of array type is used to save the data of array type that could handle upto 5 data. This process can also be named as the dynamic memory allocation which means that the object can be defined at the run time if else the data has not been measured before hand.

c) Describe any other interesting memory cells after executing line 2 :

After the execution of the second line there are 5 memory cells of the type Chicken under the variable farm are initialised and that the cells that might be used or not we could have the scope to save the data to 5 times. If then we need more number of data to be stored we then can initialise the same types of the data to the variable using the new keyword.


Hope this is helpful.

 1 Chicken farm[]; 2 farm = new Chicken[5]; Describe the memory cell farm and its contents after executing line 1 Describe the memory cell farm and its contents

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site