import java.io.IOException; public class Question72 { public Question72() throws IOException { throw new IOException(); } } public abstact class Question73 extends Question72 { public abstract void method(); }
The answer given was will cause a compiler error - a constructor must be provided which must throw an IOException or one of its super types.
I think constructors are not inherited and can not be overridden. So this answer does not make sense to me. Please explain. -Thanks.
yanish
Greenhorn
Joined: Aug 18, 2000
Posts: 21
posted
0
A parent class has a default constructor which throws IOException. But as the sub class has no any defined constructors, the compiler creates a default one but without the 'throws' clause. As parent's constructor throws a checked exception, it's needed to handle it correctly. You can do it by placing 'throws' clause in constructor definition or by using the 'try-catch' block. But created by the compiler default constructor does neither. You can look at: http://www.javaranch.com/ubb/Forum24/HTML/003480.html Some related discussion is there.
Doit
Ranch Hand
Joined: Aug 03, 2000
Posts: 169
posted
0
Thanks Yanish. One more doubt... I think default constructors gets the access modifier which is same as class access modifier. Am i right? - Thanks.