wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Question on Inheritance syntax Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Question on Inheritance syntax" Watch "Question on Inheritance syntax" New topic
Author

Question on Inheritance syntax

Rob Keefer
Greenhorn

Joined: Feb 18, 2002
Posts: 26
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 ]
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
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.
John Dale
Ranch Hand

Joined: Feb 22, 2001
Posts: 399
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.
Rob Keefer
Greenhorn

Joined: Feb 18, 2002
Posts: 26
Thanks guys...
The joys of going from C++ to Java
- Rob
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
actually Rob, in c++ its exactly the same.
constructos dont return void in c++ also. they return nothing. the same as in java.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Question on Inheritance syntax
 
Similar Threads
Why This Compiler Error?
Competition between “this”and “super” in constructor
Package Question II
Extended JFrame, use 'super'?
constructors