![]() |
Another simple problem
ERROR:
invalid method declaration; return type required invalid method declaration; return type required what's wrong here? class insertFailException extends SQLException { public insertFailedException(String reason) { super (reason); } public insertFailedException() { super(); } } |
Re: Another simple problem
On Thu, 9 Dec 2004 21:57:25 +0100, stud <ivastipancic@inet.hr> wrote:
> ERROR: > invalid method declaration; return type required > invalid method declaration; return type required > > what's wrong here? > > class insertFailException extends SQLException > { > public insertFailedException(String reason) > { > super (reason); > } > public insertFailedException() > { > super(); > } > } Compare your Constructor Names to the name of the class... Also, usually class names start with an Uppercase letter. -- Whom the gods wish to destroy they first call promising. |
Re: Another simple problem
On Thu, 9 Dec 2004 21:57:25 +0100, stud wrote:
> Sub: Another simple problem Simple problems are best dealt with on a different group. <http://www.physci.org/codes/javafaq.jsp#cljh> > ERROR: > invalid method declaration; return type required > invalid method declaration; return type required > > what's wrong here? For resolving problems, start here. <http://www.physci.org/codes/javafaq.jsp#exact> > class insertFailException extends SQLException > { > public insertFailedException(String reason) This is because you failed to follow-up on the advice that Paul van Rossem (and possibly others) pointed out in your 'Simple Problem' thread. -- Andrew Thompson http://www.PhySci.org/codes/ Web & IT Help http://www.PhySci.org/ Open-source software suite http://www.1point1C.org/ Science & Technology http://www.LensEscapes.com/ Images that escape the mundane |
Re: Another simple problem
The constructor name has to be the same as the class name.
|
Re: Another simple problem
In article <cpae76$qo$1@sunce.iskon.hr>, stud (ivastipancic@inet.hr)
dropped a +5 bundle of words... > ERROR: > invalid method declaration; return type required > invalid method declaration; return type required > > what's wrong here? > > class insertFailException extends SQLException > { > public insertFailedException(String reason) > { > super (reason); > } > public insertFailedException() > { > super(); > } > } > You need either a return type or void for your method. public String zoom() { } public void zoomZoom() { } -- Starshine Moonbeam mhm31x9 Smeeter#29 WSD#30 sTaRShInE_mOOnBeAm aT HoTmAil dOt CoM |
Re: Another simple problem
In article <MPG.1c2285a5761e6489989fa1@news.alt.net>, Starshine Moonbeam
(silverbells@tacoshells.com) dropped a +5 bundle of words... > In article <cpae76$qo$1@sunce.iskon.hr>, stud (ivastipancic@inet.hr) > dropped a +5 bundle of words... > > > ERROR: > > invalid method declaration; return type required > > invalid method declaration; return type required > > > > what's wrong here? > > > > class insertFailException extends SQLException > > { > > public insertFailedException(String reason) > > { > > super (reason); > > } > > public insertFailedException() > > { > > super(); > > } > > } > > > > You need either a return type or void for your method. > > public String zoom() { > > } > > public void zoomZoom() { > > } > However, you're using constructors which don't have the same name as your class, which is why Java thinks it's a method. -- Starshine Moonbeam mhm31x9 Smeeter#29 WSD#30 sTaRShInE_mOOnBeAm aT HoTmAil dOt CoM |
Re: Another simple problem
klynn47@comcast.net scribbled the following:
> The constructor name has to be the same as the class name. Which is something that has lately struck me as needless. Why not have a special keyword for constructors? Such as "new"? For example: public class Foobar { public new() { /* ... */ } public new(int foo, int bar) { /* ... */ } } There is no loss of information, because every constructor in the same class must have the same name anyway. -- /-- Joona Palaste (palaste@cc.helsinki.fi) ------------- Finland --------\ \-------------------------------------------------------- rules! --------/ "Remember: There are only three kinds of people - those who can count and those who can't." - Vampyra |
Re: Another simple problem
Joona I Palaste <palaste@cc.helsinki.fi> wrote:
> Which is something that has lately struck me as needless. Why not have > a special keyword for constructors? Such as "new"? For example: > > public class Foobar { > public new() { > /* ... */ > } > public new(int foo, int bar) { > /* ... */ > } > } I certainly don't see a compelling argument against that syntax, and it would certainly avoid a couple newbie pitfalls. However, I don't see the kind of compelling interest that would result in a language change for it after the fact. -- www.designacourse.com The Easiest Way To Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation |
Re: Another simple problem
"Joona I Palaste" <palaste@cc.helsinki.fi> wrote in message news:cpcdcu$qo5$1@oravannahka.helsinki.fi... > klynn47@comcast.net scribbled the following: >> The constructor name has to be the same as the class name. > > Which is something that has lately struck me as needless. Why not have > a special keyword for constructors? Such as "new"? For example: > > public class Foobar { > public new() { > /* ... */ > } > public new(int foo, int bar) { > /* ... */ > } > } > > There is no loss of information, because every constructor in the same > class must have the same name anyway. Cool. Of course, the old verbose, less clear notation public class Foobar { public Foobar () { /* ... */ } public Foobar (int foo, int bar) { /* ... */ } } would still have to be legal. But who would use it instead of your suggestion in new code. George |
Re: Another simple problem
What if you wanted a method called new() under Foobar obj?
And I think it might add needless complexity to the compiler & code if you used: - Car car = new New(); rather than Car car = new Car(); no? How would you initialise the Car object? Same way as before? But then the Car() method call doesn't make sense. I guess you could do: car = new(toyota); Which I think is just as confusing (if not more so in the object) if you simply used the class name as the constructor. -- Waheed Islam wislam@gmail.com http://www.wislam.co.uk/ |
| All times are GMT. The time now is 03:59 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.