Mitu Gabriel
Mitu Gabriel

Reputation: 17

Overriding GroupLayout constructor in Java

Why can't I add a constructor in class GroupLayout like:

public class xxx extends GroupLayout {

  public xxx(Container host, String...arg) {
    //code
  }
}

Upvotes: 1

Views: 39

Answers (1)

craigcaulfield
craigcaulfield

Reputation: 3538

GroupLayout doesn't have a no-argument constructor meaning Java can't make an implicit call to it's constructor, so you'd be getting a compile-time error about that. You just need to call super(host) as the first line of your method to invoke the constructor that GroupLayout does have. Try:

public class SubGroupLayout extends GroupLayout {

    public SubGroupLayout(Container host, String ...arg) {
        super(host);
        // then, do your own code here
    }
}

See Using the Keyword super and super() in constructor for more details.

Upvotes: 0

Related Questions