I though constructor are never inherited!!, According to me the answer should be 1), but again there is the limitation of keeping super on the first line. Please help!!! Read the following piece of code carefully.
Assume that the defination of Question72E begins with the line public class Question72E extends Question72 It is required that none of the constructors of Question72E should throw any checked exception.
1) It can be achived by placing the call to the superclass with a super keyword , which is placed in a try block with a catch block to handle the IOException thrown by the super class. 2) It can be achived by avoiding explicit calls to the base class constructor. 3) It cannot be done in the Java Laungage with the above definition of the base class.
Amish Answer one is false because if the first line of a constructor is not this(xxx) or super(xxx) the compiler puts in a call to the default superclass constructor. So you can't call the super class constructor from within a try-catch block. Answer 2 wont work because even if you dont explicitly call the base class constructor the call is still supplied by the compiler. Given the requirment that you can't throw an exception from the new class' constructor and if you can't change the base class then it can't be done. hope that helps [ January 14, 2002: Message edited by: Dave Vick ]
Maybe helpful Amish: Constructors are not inherited. But because they are chained together along the hierarquy up to Object, constructing an object of subclass will always throw the exceptions that the superclass throws because the base constructor will be called. That is why a constructor in the derived class must declare all the checked exceptions that the base class declare. Though, it can declare more, the ones that the construction of the proper derived object might throw.