Consider the following class:
public class MyBaseClass{ public MyBaseClass (int port) throws IOException{ //...lot of valid code. } //...other valid code. }
You want to write another class MyClass that extends from MyBaseClass.
Which of the following statements should hold true for MyClass class?
Select 1 option
Correct Option is : F
As MyBaseClass has only one constructor, there is only one way to instantiate it.
To instantiate any subclass of MyBaseClass, the subclass's constructor should call super(int).
But that throws throws IOException.
And so it must be defined in the throws clause of subclass's constructor.
Note that you cannot do something like:
public MyClass (){ try{ super (); }catch (Exception e){} //WRONG : call to super must be firs }
Constructor must declare all the checked exceptions declared in the base constructor.
They may add other exception.