• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Constructors

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 can't renounce my name. It's on all my stationery! And hinted in this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic