| Author |
exception doubt
|
dolly shah
Ranch Hand
Joined: Jun 18, 2007
Posts: 383
|
|
What will be the output? A1 A Class Test10 Class A2 Runtimxception A3 no output A4 Compiler Error -answer Why compiler error shows me at "Test20(int i){}" unhandled exception? Can anybody explain?
|
SCJP-1.5<br />SCWCD-1.4
|
 |
christian combarel
Ranch Hand
Joined: Aug 04, 2007
Posts: 47
|
|
Hi, If you instanciate Test20 using the Test20(int i){} constructor, the A3() will be called. As A3() declare an Exception, it must be declared too with Test20(int i){}.
|
-------------
Chris
|
 |
dolly shah
Ranch Hand
Joined: Jun 18, 2007
Posts: 383
|
|
|
If you instanciate Test20 using the Test20(int i){} constructor. That means what? What you want to say I am not getting. Can you explain little more?
|
 |
Praveen Seluka
Ranch Hand
Joined: Jul 17, 2007
Posts: 95
|
|
Hi If a superclass constructor throws Exception,then whether subclass constructor should also declare throws Exception Thanks Praveen SP
|
 |
Lucky J Verma
Ranch Hand
Joined: Apr 11, 2007
Posts: 277
|
|
Test20(int i ) constructor will call Parent class A3's no-arg constructor ,unless super is mentioned A3() constructor throws Exception ,so caller method must also have a way to handle the exception. In case A3() has no-exception clause,it wolud have run.
|
 |
Praveen Seluka
Ranch Hand
Joined: Jul 17, 2007
Posts: 95
|
|
|
Thanks Lucky verma,I got it.
|
 |
 |
|
|
subject: exception doubt
|
|
|