Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Java private no-arg constructor

class Main {

  int i;

  // constructor with no parameter
  private Main() {
    i = 5;
    System.out.println("Constructor is called");
  }

  public static void main(String[] args) {

    // calling the constructor without any parameter
    Main obj = new Main();
    System.out.println("Value of i: " + obj.i);
  }
}
Source by softhunt.net #
 
PREVIOUS NEXT
Tagged: #Java #private #constructor
ADD COMMENT
Topic
Name
9+8 =