• 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

Head First Java SonofBoo question

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In ch.9 of this book, it talks about constructors.

It asks you to id the subclass constructors that would not compile. I id 2 of the 3. The one I am not sure of is:

//super class

public class Boo {
public Boo(int i) {}
public Boo(String s) {}
public Boo(String s, int i) {}

//subclass

class SonOfBoo extends Boo {

public SonOfBoo(int i, String s) {} //This is the one I am not sure.
//If it has a statement: super(i, s);
// I know it would be wrong because the variables' type does not match up with the order of variable type in the superclass's constructors

However, since it has no super statement at all, does it just mean it is an invalid constructor?? I am not sure if the author is suggesting there is no statement under this sublass constructor or it is suggesting there are statements implied.

If someone can help me, I would be appreciated.

Thanks!





 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Peter Pay wrote:However, since it has no super statement at all, does it just mean it is an invalid constructor?? I am not sure if the author is suggesting there is no statement under this sublass constructor or it is suggesting there are statements implied.

If someone can help me, I would be appreciated.


If you don't supply a super(whatever) statement yourself, the compiler will add
super();

So, the question you need to ask yourself is: does the superclass have a constructor that matches what the compiler adds?

Winston
 
Ranch Hand
Posts: 78
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you try to compile this


there will be a compilation error saying that "class Boo have no constructors which takes zero arguments". Because the compiler will implicitly create a Default (Parameterless) constructor if and only if there are no other constructors explicitly defined.

Best Wishes.
 
reply
    Bookmark Topic Watch Topic
  • New Topic