Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

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;
    }
}
Source by tutorials.jenkov.com #
 
PREVIOUS NEXT
Tagged: #syntax #constructor #java
ADD COMMENT
Topic
Name
7+4 =