Menu
Topics Index
...
`

Methods1470


If you need explanation Read this topic

If you need Answer Take test on this topic

Methods1470
What will be the output of the following program?
public class MyClass {
    public static void main(String srit[]) {
        myMethod();
    }
    static void myMethod() {
        int x, y;
        x = 5;
        y = 3;
        System.out.print("(" + x + ", " + y + ")");
        points(x, y);
        System.out.print(" (" + x + ", " + y + ")");
    }
    static void points(int x, int y) {
        int xy;
        xy = x;
        x = y;
        y = xy;
        System.out.print(" (" + x + ", " + y + ")");
    }
}

A. (5, 3) (3, 5) (3, 5)
B. (5, 3) (5, 3) (5, 3)
C. (5, 3) (3, 5) (5, 3)
D. Compilation Error
E. Runtime Error
Topic: Java Methods - Parameter Passing And Scope

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 is C...in myMethod() x is 5 n y is 3 n then in points () method x n y are swaped...and it prints(3,5) as x,y are local variables the change done in points() is not reflected in myMethod() so the second print statement prints (5,3)

Posted by Santosh Munugota    2013-06-21 08:16:45


answer is c since in constructor x and y are initialised to 5 and 3;so it prints (5,3) and then in points method x and y are swaped.so in point method print statement prints (3,5) and then in constructor ,the change in values of x and y are not affected,and so the print statement prints (5,3)

Posted by Sheetal Agrawal    2013-06-21 10:21:26


Congratulations Santosh Munugota. You are this dose winner. Please send us your mobile details and we will process the recharge asap.

Posted by Merit Campus    2013-06-21 12:37:32


got RC! :)

Posted by Santosh Munugota    2013-06-28 09:51:08


© meritcampus 2019

All Rights Reserved.

Open In App