Tuesday, 26 March 2019

UGC NET Computer Science July 2018 - II | Question 3

Question 3
3. What is the output of the following JAVA program ?
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

Options:
  1. (1) 12 : 15
  2. (2) 15 : 12
  3. (3) 12 : 12
  4. (4) 15 : 15
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   

PreviousNext
UGC-NET CS 2018 July - II Question 2UGC NET CS 2018 July - II Question 4

No comments:

Post a Comment

UGC NET Computer Science December 2019 | Question 16

Question 16 In a certain coding language. 'AEIOU' is written as 'TNHDZ'. Using the same coding language. 'BFJPV' wil...

Popular Posts