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

This question was previously asked in
UGC NET Computer Science (Paper 2) July 2018 Paper
View all UGC NET Papers >
  1. 12 : 15
  2. 15 : 12
  3. 12 : 12
  4. 15 : 15

Answer (Detailed Solution Below)

Option 4 : 15 : 15
Free
UGC NET Paper 1: Held on 21st August 2024 Shift 1
50 Qs. 100 Marks 60 Mins

Detailed Solution

Download Solution PDF

Consider the given code :

STEP 1 :

class simple

{

public static void main(String[ ] args)

{

simple obj = new simple( );               / it creates an object of class simple

obj.start( );                                          / then calls the function start

}

STEP 2:

void start( )

{

long [ ] P= {3, 4, 5};          / it creates an array with three integers.

long [ ] Q= method (P);        /* function method P is called here, which is then reflected in  array Q */

System.out.print (P[0] + P[1] + P[2]+”:”);

System.out.print (Q[0] + Q[1] + Q[2]);

}

STEP 3 :

long [ ] method (long [ ] R)

{

R [1]=7;               /*it indirectly change the value of second element of array to 7 which reflects in array Q. Also address of P is passed as an argument, it changes the value of array P second element to 7 */

return R;

}

STEP 4:

Now ,  Array P becomes , long [ ] P= {3, 7, 5};       

Array Q becomes , long [ ] Q= {3, 7, 5};            

System.out.print (P[0] + P[1] + P[2]+”:”);             / it print the sum of elements of array P i.e. (3+7+5 = 15)

System.out.print (Q[0] + Q[1] + Q[2]);             // it print the sum of elements of array Q i.e. (3+7+5 = 15)

Latest UGC NET Updates

Last updated on Jun 6, 2025

-> The UGC NET Exam Schedule 2025 for June has been released on its official website.

-> The UGC NET Application Correction Window 2025 is available from 14th May to 15th May 2025.

-> The UGC NET 2025 online application form submission closed on 12th May 2025.

-> The June 2025 Exam will be conducted from 21st June to 30th June 2025

-> The UGC-NET exam takes place for 85 subjects, to determine the eligibility for 'Junior Research Fellowship’ and ‘Assistant Professor’ posts, as well as for PhD. admissions.

-> The exam is conducted bi-annually - in June and December cycles.

-> The exam comprises two papers - Paper I and Paper II. Paper I consists of 50 questions and Paper II consists of 100 questions. 

-> The candidates who are preparing for the exam can check the UGC NET Previous Year Papers and UGC NET Test Series to boost their preparations.

More Java Questions

Hot Links: dhani teen patti teen patti master gold apk teen patti customer care number teen patti master gold