Oct 10, 2018

[HDGEM] How to call a constructor from another class in Java

public class Foo {      private int x;        public Foo() {          this(1);      }        public Foo(int x) {          this.x = x;      }  }
To chain to a particular superclass constructor instead of one in the same class, use superinstead of this
Note that you can only chain to one constructor, and it has to be the first statement in your constructor body.

Posted By Blogger to HDGEM at 2/16/2017 09:52:00 AM