Answers for "this() java constructor"

1

syntax of a constructor in java

public class MyClass {//this is an example of a class with a non default constructor  
    private int number = 0;

    public MyClass() {
    }

    public MyClass(int theNumber) {//this is the constructor
        //acces modifiers+constructor name(it needs to be the same as the class name)+parameters
        this.number = theNumber;
    }
}
Posted by: Guest on November-15-2021
0

calling this in constructor java

In Java another constructor of the same class can be called from a
  constructor via this().
 Note however that this has to be on the first line.
Posted by: Guest on February-14-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language