File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Constructors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Constructors" Watch "Constructors" New topic


Ranch Hand

Joined: Aug 03, 2000
Posts: 169
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.

Joined: Aug 18, 2000
Posts: 21
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:
Some related discussion is there.
Ranch Hand

Joined: Aug 03, 2000
Posts: 169
Thanks Yanish.
One more doubt...
I think default constructors gets the access modifier which is same as class access modifier. Am i right?
- Thanks.
I agree. Here's the link:
subject: Constructors
It's not a secret anymore!