| Author |
Exception problem
|
Rippon Jalali
Greenhorn
Joined: Aug 25, 2006
Posts: 23
|
|
Can anybody tell me why this program is giving compiler error. In my opinion it should run fine as first Test11() constructior will b called the implicit call to super which is valid too. public class Test11 extends A{ Test11()throws Exception{ System.out.println("Test10 Class"); } Test11(int i){} public static void main(String args[]) throws Exception{ Test11 t = new Test11(); } } class A{ A() throws Exception{ System.out.println("A Class"); } }
|
 |
Joanne Neal
Rancher
Joined: Aug 05, 2005
Posts: 3011
|
|
The only error I get is that the Test11 constructor that takes an int should be declared to throw an exception, which is what I would expect as the parent class constructor that it implicitly calls is declared to throw an Exception. [ January 05, 2007: Message edited by: Joanne Neal ]
|
Joanne
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24057
|
|
Hi, Welcome to JavaRanch! We have a strict policy on display names, which must be a real first and last name with a space between. Please go here and fix your display name up, pronto. Thanks, pardner!
|
[Jess in Action][AskingGoodQuestions]
|
 |
Rippon Jalali
Greenhorn
Joined: Aug 25, 2006
Posts: 23
|
|
|
Thank you Neal But i am not using that constructor any where in my code .So what is the need of that..
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16692
|
|
Originally posted by Rippon Jalali: Thank you Neal But i am not using that constructor any where in my code .So what is the need of that..
The compiler is *not* that smart. If you have a constructor that have a compile error, it is an error condition. It will not allow you to have errors in it just because you are not using it. Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Rippon Jalali
Greenhorn
Joined: Aug 25, 2006
Posts: 23
|
|
|
i got it. thanks henry and Neal
|
 |
 |
|
|
subject: Exception problem
|
|
|