Given the following code snippet;

int salaries[];
int index = 0;
salaries = new int[4];
while (index < 4)
{
salaries[index] = 10000;
index++;
}
What is the value of salaries [3]?

Options
- 40000
- 50000
- 15000
- 10000


CORRECT ANSWER : 10000

Discussion Board
O/P=10000

Its correct, no compliation error.
O/P=10000.

VP 11-27-2014 02:07 AM

Output

The value of the salary would be 10000. There is an error in the code as mentioned previously the code would be defined as:

salaries=new int salaries[4]

then it can be defined as

salaries=new int[4]

but in java the initialization needs to be done as per the norms and new method is used to create the instance dynamically.

As the increment is going on but out of the options given it is close to the output as 10000.

Rohit Sharma 07-28-2014 03:23 AM

Correction

change it :)

salaries = new int salaries[4]; => salaries = new int[4];



Shiva 07-21-2014 10:58 PM

Output is worng for this question

Output is compilation error because "salaries = new int salaries[4];".

Oleti Kiran 01-21-2014 12:48 AM

Write your comments

 
   
 
 

Enter the code shown above:
 
(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)


Advertisement