Question 3
3. What is the output of the following JAVA program ?
Answer : (4) 15 : 15
Explanation Question 3
long [] Q will contains the updated array [3,7,5] returned by the method(P) and the value passed to function as array. So, modification to array reflected to the passed array P.
Actually arrays are passed as reference. So, whatever changes you make in R, it actually gets reflected in P.
Hence both the arrays will display sum=3+7+5=15. So, prints 15:15
long [] Q will contains the updated array [3,7,5] returned by the method(P) and the value passed to function as array. So, modification to array reflected to the passed array P.
Actually arrays are passed as reference. So, whatever changes you make in R, it actually gets reflected in P.
Hence both the arrays will display sum=3+7+5=15. So, prints 15:15
Previous | Next |
UGC-NET CS 2018 July - II Question 2 | UGC NET CS 2018 July - II Question 4 |
class simple
{
public static void main(String[ ] args)
{
simple obj = new simple( );
obj.start( );
}
void start( ){
long [ ] P= {3, 4, 5};
long [ ] Q= method (P);
System.out.print (P[0] + P[1] + P[2]+”:”);
System.out.print (Q[0] + Q[1] + Q[2]);
}
long [ ] method (long [ ] R)
{
R [1]=7;
return R;
}
} //end of class