File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

Constructors

Doit
Ranch Hand

Joined: Aug 03, 2000
Posts: 169
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
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
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: http://aspose.com/file-tools
 
subject: Constructors