Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Another simple problem (http://www.velocityreviews.com/forums/t139111-another-simple-problem.html)

stud 12-09-2004 08:57 PM

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();
}
}



Stefan Schulz 12-09-2004 09:29 PM

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.

Andrew Thompson 12-09-2004 09:31 PM

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

klynn47@comcast.net 12-09-2004 09:36 PM

Re: Another simple problem
 
The constructor name has to be the same as the class name.


Starshine Moonbeam 12-09-2004 09:54 PM

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










Starshine Moonbeam 12-09-2004 10:18 PM

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










Joona I Palaste 12-10-2004 02:55 PM

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

Chris Smith 12-10-2004 03:14 PM

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

George W. Cherry 12-11-2004 02:16 AM

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



wislam 12-11-2004 02:54 PM

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.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57