aspose file tools*
The moose likes Beginning Java and the fly likes Head First Java SonofBoo question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Head First Java SonofBoo question" Watch "Head First Java SonofBoo question" New topic
Author

Head First Java SonofBoo question

Peter Pay
Greenhorn

Joined: Sep 29, 2009
Posts: 7
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!





Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7771
    
  21

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


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Avinash Ga
Ranch Hand

Joined: Aug 13, 2011
Posts: 78

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.


Avinash G.A
OCP Java SE 6 Programmer, OCP Java EE 5 Web Component Developer, OCE Java EE 6 Web Services Developer, VMware Certified Core Spring 3.x Developer, EMC Proven Professional (ISM-V2)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Head First Java SonofBoo question