If arrays cannot be resized , Why is this code valid <br /> <br /> String[] strArray = new String[2];<br /> strArray = new String[5];
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Interview Questions and Answers

 Q1. If arrays cannot be resized , Why is this code valid

String[] strArray = new String[2];
strArray = new String[5];
Core Java
Ans. We are not resizing the first array here but assigning the reference strArray to a new Array with size 5.

So after line 2, We have 2 arrays in memory, one with size 2 and other with size 5 with strArray referring to second array with size 5.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arrays  array initialization


Related Questions

 Can we declare an array without assigning the size of an array?
 Is this array declaration correct ? If not , Why ?

String[] strArray = new String[];
 Is this array initialization correct ? If Yes, What will be the size of array ?

String[] strArray = new String[]{"Buggy","Bread"};
 Is this array initialization correct ? If Yes, What will be the size of array ?

String[] strArray = new String[3]{"Buggy","Bread"};
 Is this code valid

String[] strArray = new String[2];
strArray.length = 5;



Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: