recategorized by
4,344 views
1 votes
1 votes

 

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
  1. 12:15
  2. 15:12
  3. 12:12
  4. 15:15
recategorized by

3 Answers

3 votes
3 votes
Answer is 4 15:15

1. p=3,4,5

2. q=3,7,5

when we have the statement long[]Q=method(P)

 

It will call method function and p is passed as parameter and in method function we are changing r[1]=7.

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
0 votes
0 votes

D. 15:15

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

because 'method' function is called before printing values of P and thus it has updated values of P also.

Related questions

3.8k
views
3 answers
0 votes
Pooja Khatri asked Jul 13, 2018
3,803 views
In Java, which of the following statements is/are TRUE?S1: The final' keyword applied to a class definition prevents the class form being extended through derivationS2: A ... :S1 and S2 onlyS1 and S3 onlyS2 and S3 onlyAll of S1, S2 and S3
1.5k
views
1 answers
0 votes
Pooja Khatri asked Jul 13, 2018
1,533 views
Which of the following statements is/are true?P: C programming language has a weak type system with static types.Q: Java programming language has a string type system with static typesCode:P onlyQ onlyBoth P and QNeither P nor Q
2.8k
views
3 answers
2 votes
makhdoom ghaya asked Oct 4, 2016
2,753 views
Java uses threads to enable the entire environment to be ______.SymmetricAsymmetricSynchronousAsynchronous
2.6k
views
1 answers
1 votes
makhdoom ghaya asked Oct 1, 2016
2,552 views
Which of the following is not a correct statement ?Every class containing abstract method must be declared abstract.Abstract class can directly be ... can be initiated.Abstract class does not contain any definition of implementation.