Menu
Topics Index
...
`

Method calling


If you need explanation Read this topic

If you need Answer Take test on this topic

Method calling
What will be the output of the following program?
public class ObjectArray
{
    public static void passByReference(String a[])
    {
        a[0] = "Changed";
    }
    public static void main(String args[])
    {
        String[] b = {"Apple", "Mango", "Orange"};
        System.out.println("Before Function Call    " + b[0]);
        ObjectArray.passByReference(b);
        System.out.println("After Function Call    " + b[0]);
    }
}

A. Before Function Call    Apple
After Function Call    Changed
B. Before Function Call    Apple
After Function Call    Apple
C. Before Function Call    Changed
After Function Call    Changed
D. Compilation Error or Runtime Error
Topic: Unknown

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ans A:passbyref sends the string array then apple will cahnged to changed...

Posted by Bheema Reddy    2014-02-20 03:44:48


Here the string array is passed by reference and if we make any modifications to the array in the called function, it will be reflected in the calling function as well. The called function makes a change to the first element of string array in this program. So the answer is A.

Posted by Shaileshwar Sharma    2014-02-20 04:00:37


ans is :A  because ..in the first statement it will print the array first variable name as Apple..and then in 2nd statement ..here it calls class static method ....it can be call through its class name only...so we will get the answer "Changed " will be printed so...answer is : A

Posted by Sapparapu Pradeep Kumar    2014-02-20 06:49:46


Congratulations Bheema Reddy. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-02-21 05:35:38


© meritcampus 2019

All Rights Reserved.

Open In App