Question
Download Solution PDFWhat 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 classAnswer (Detailed Solution Below)
Detailed Solution
Download Solution PDFConsider 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)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.