Question 799 – OOPS
November 29, 2023
Question 2545 – OOPS
November 29, 2023
Question 799 – OOPS
November 29, 2023
Question 2545 – OOPS
November 29, 2023

Question 795 – OOPS

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

Correct Answer: D

Question 46 Explanation: 
• First we will create the object of simple class.
• By using object , we call the function start( ).
• In the start() function definition, first statement is integer array with three elements.
• long [ ] Q= method (P); Again function method(p) will be called.
• In the definition of method function, we are changing the second element of array to value 7 and returning updated array to array Q.
• We are passing address of P as argument to method so Modifications happened in the method automatically reflects to array P.
• Both array P and Q consists of values {3,7,5}.
• The sum of the three values are 15.
A
12 : 15
B
15 : 12
C
12 : 12
D
15 : 15
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!