The following code gives the errors listed below it. I have found some work arounds, but am wondering why this doesn't work. Can someone explain? - Rob ----- Begin Code -----
--- Begin Error Messages --- FooBar.java:7: cannot resolve symbol symbol : constructor Foo (java.lang.String) location: class Foo Foo foo = new Foo( new String("Hello, world")); ^ FooBar.java:41: call to super must be first statement in constructor super(); ^ FooBar.java:46: call to super must be first statement in constructor super( bs ); ^ 3 errors (edited by Cindy to format code) [ February 24, 2002: Message edited by: Cindy Glass ]
you didnt name your constructors right. constructors CANT return anything. not even void. constrcutors are special function that return nothing and are called in the creation of objects. modify all your constrcutors and remove the void keyword from them. ps. u dont need to extend from Object. all classes extend from Object by default. no need to write it.
You put a return type (void) in the signatures of what you intended to be the constructors. A constructor does not have a return type. The return type (void) makes it an ordinary method, albeit one with a badly chosen name. And super() is legal only as the first statement of a constructor, never in an ordinary method. Since you didn't specify a valid constructor, the only constructor you have is the default no-arg constructor that Java creates when you don't specify a constructor.
Joined: Feb 18, 2002
Thanks guys... The joys of going from C++ to Java - Rob
Roy Ben Ami
Joined: Jan 13, 2002
actually Rob, in c++ its exactly the same. constructos dont return void in c++ also. they return nothing. the same as in java.