aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes about Constructor signature declared to be throws Exception 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 "about Constructor signature declared to be throws Exception" Watch "about Constructor signature declared to be throws Exception" New topic
Author

about Constructor signature declared to be throws Exception

Pratap koritala
Ranch Hand

Joined: Sep 27, 2006
Posts: 252
How can a construcor declared that it throws Exception,wat is the use of the declaration, the block that uses constructor must be enclosed in "TRY" or not. and wat about the inherited class construtor(the Question is some what ambiguous)

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9384
    
    2

Yes you are right. super must be the first statement in a subclass constructor. In the above situation you can just say that the constructor in the subclass also throws the same exception.


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Satish Kota
Ranch Hand

Joined: Feb 08, 2006
Posts: 88
Originally posted by ramya sri:
How can a construcor declared that it throws Exception,wat is the use of the declaration, the block that uses constructor must be enclosed in "TRY" or not. and wat about the inherited class construtor(the Question is some what ambiguous)



super() must be the 1st statement. Hence the only way a subclass constructor handles the exception is by declaring that it throws it, in such case the method which instantiates this class must handle or declare exception. See this example:



SCJP 5.0 77%
 
jQuery in Action, 2nd edition
 
subject: about Constructor signature declared to be throws Exception