Filling in the Gaps

Java Puzzler – Super must be first line in constructor

Posted by: Admin on: March 4, 2009

Why do you get a compiler error about super() needing to be the first line in a constructor with this code?

public class Foo {
public void Foo() {
super();
}
}

answer after the jump…

public void Foo() isn’t a constructor, it’s a method, since constructors don’t have a return type – the error message is a little misleading!

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.