Sunday, 19 May 2013

Exception - 3 -


package net.dharmaraj;

import java.io.*;

class Base
{
    public static void amethod() throws FileNotFoundException
    {
        System.out.println("amethod BASE");
    }
}

class ExcepDemo extends Base
{
    public static void main(String argv[])
    {
        ExcepDemo e = new ExcepDemo();
    }

    public static void amethod()
    {
        System.out.println("amethod Child");
    }

    protected ExcepDemo()
    {
        try
        {
            DataInputStream din = new DataInputStream(System.in);
            System.out.println("Pausing");
            din.readChar();
            System.out.println("Continuing");
            this.amethod();
            super.amethod();
        }
        catch (IOException ioe)
        {
        }
    }
}



What will happen when you attempt to compile and run the following code


1)Compile time error caused by protected constructor
2) Compile time error caused by amethod not declaring Exception
3) Runtime error caused by amethod not declaring Exception
4) Compile and run with output of "Pausing" and "Continuing" after a key is hit



Console Out Put:


Error: Could not find or load main class net.dharmaraj.Ppvg


No comments:

Post a Comment