OOPS
November 29, 2023OOPS
November 29, 2023OOPS
Question 89 |
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
12 : 15 | |
15 : 12 | |
12 : 12 | |
15 : 15 |
Question 89 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.
• 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.
Correct Answer: D
Question 89 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.
• 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.
Subscribe
Login
0 Comments