Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Java private no-arg constructor

class Main {

  int i;

  // constructor with no parameter
  private Main() {
    i = 15;
    System.out.println("Constructor 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
8+3 =