Friday, 10 May 2013

Constructor - 8 -


Given the following code how could you invoke the Base constructor that will print out the string "base constructor";


package net.dharmaraj;
class Base
{
    Base(int i)
    {
        System.out.println("base constructor");
    }

    Base()

    {
    }
}

public class Sup extends Base

{
    public static void main(String argv[])
    {
        Sup s = new Sup();

        // One

    }

    Sup()

    {
        super(10);
        // Two
    }

    public void derived()

    {

        // Three

    }
}




1) On the line After //One put Base(10); 
2) On the line After //One put super(10); 
3) On the line After //Two put super(10); 
4) On the line After //Three put super(10);


Answer:--

base constructor

No comments:

Post a Comment