Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception problem

 
Rippon Jalali
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Rippon Jalali
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21000
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rippon Jalali
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i got it. thanks henry and Neal
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic