Menu
Topics Index
...
`

Creating AWT point


If you need explanation Read this topic

If you need Answer Take test on this topic

Creating AWT point
What will be the output of the following program?
import java.awt.*;
public class Tricky {
    public static void main(String[] args) {
        int a = 7;
        int b = 9;
        Point p1 = new Point(2, 2);
        Point p2 = new Point(2, 2);
        getPrint(a, p1);
        System.out.println(a + " " + b + " " + p1.x + " " + p2.x);
        getPrint(b, p2);
        System.out.println(a + " " + b + " " + p1.x + " " + p2.x);
    }
    public static void getPrint(int a, Point p1) {
        a = a + a;
        p1.x = a;
        System.out.print(a + " " + p1.x + " - ");
    }
}

A. 14 14 - 7 9 14 2
14 14 - 7 9 14 2
B. 14 14 - 7 9 14 2
18 18 - 7 9 14 18
C. 14 14 - 7 9 14 2
18 18 - 7 9 14 2
D. Some other output
E. Compilation Error or Runtime Error
Topic: Other Advanced Topics In Java

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 b....after calling getprint the value 14 14 is printed and the value of a,b and p1.x,p2.x are printed..Similarly,the next sop prints the corresponding values

Posted by Badam Swathi    2014-06-20 14:54:20


Answer : B in the first getPrint() we change the value of p1.x to 14 coz of a=a+a and in the second getPrint() we change the value of p2.x as the object being passed is p2 in the call

Posted by Deepak Kumar Yadav    2014-06-20 14:55:26


ans b.getprint insid prints 14 14,
main() prints 7 914 2
2nd 18 18 insid func 7 9 14 18 printd outsid

Posted by Maheshwari Natarajan    2014-06-20 14:57:55


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

Posted by Merit Campus    2014-06-23 04:41:04


© meritcampus 2019

All Rights Reserved.

Open In App