Friday, 10 May 2013

Constructor - 4 -

Given the following code what will be the output?



package net.dharmaraj;

class ValHold

{
    public int i = 10;
}

public class ObParm

{
    public static void main(String argv[])
    {
        ObParm o = new ObParm();
        o.amethod();
    }

    public void amethod()

    {
        int i = 99;
        ValHold v = new ValHold();
        v.i = 30;
        System.out.println("1st-->    " + i);
        another(v, i);

        System.out.println("2nd-->    " + v.i);

    }// End of amethod

    public void another(ValHold v, int i)// 

    {
        i = 0;
        v.i = 20;
        ValHold vh = new ValHold();
        v = vh;
        System.out.println(v.i + " " + i);
    }// End of another
}






1) 10,0, 30
2) 20,0,30
3) 20,99,30
4) 10,0,20



Answer:--


1st-->    99
10 0
2nd-->    20

No comments:

Post a Comment