Friday, 10 May 2013

Constructor - 10 -

 What will appear in the standard output when you run the Tester class? 


package net.dharmaraj;

public class Tester

{
    int var;

    Tester(double var)

    {
        // this.var;
        this.var = (int) var;
        System.out.println(this.var);
        System.out.println(var);
    }

    Tester(int var)

    {
        this("hello");
    }

    Tester(String s)

    {
        this();
        System.out.println(s);
    }

    Tester()

    {
        System.out.println("good-bye");
    }

    public static void main(String[] args)

    {
        Tester t = new Tester(5.0);
        // Tester t = new Tester(5);
    }
}



a) nothing 


b) "hello" 
c) 5 
d) "hello" followed by "good-bye" 
e) "good-bye" followed by "hello" 


Answer:--


5
5.0


No comments:

Post a Comment