java constructor
class MyClass { public MyClass () { //constructor code } }
constructor in java
when the class is run the constructor also run
java constructor example
class Main { private String website; // constructor Main() { website = "'softhunt.net'"; } public static void main(String[] args) { // constructor is invoked while // creating an object of the Main class Main obj = new Main(); System.out.println("Welcome to " + obj.website); } }
Source: softhunt.net