• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question on Inheritance syntax

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys...
The joys of going from C++ to Java
- Rob
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
actually Rob, in c++ its exactly the same.
constructos dont return void in c++ also. they return nothing. the same as in java.
 
reply
    Bookmark Topic Watch Topic
  • New Topic