Search
 
SCRIPT & CODE EXAMPLE
 

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);
  }
}
Comment

Java public no-arg constructor

class Tutorialweb {
  String website;

  // public constructor
  public Tutorialweb() {
    website = "Softhunt.net";
  }
}

class Main {
  public static void main(String[] args) {

    // object is created in another class
    Tutorialweb obj = new Tutorialweb();
    System.out.println("Tutorial website name = " + obj.website);
  }
}
Comment

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);
  }
}
Comment

Java public no-arg constructors

class Company {
  String name;

  // public constructor
  public Company() {
    name = "Programiz";
  }
}

class Main {
  public static void main(String[] args) {

    // object is created in another class
    Company obj = new Company();
    System.out.println("Company name = " + obj.name);
  }
}
Comment

PREVIOUS NEXT
Code Example
Java :: where to check when you hava a error 
Java :: plantuml java 
Java :: android java update image dynamically 
Java :: concatenar java 
Java :: okhttpconfig 
Java :: validate data type in request body spring validation 
Java :: Sample NavigableMap 
Java :: how to extract a set of binary strings in java 
Java :: using new to create arrays 
Java :: 2 multiples recursion 
Java :: java herencia 
Java :: java dictionary array initialization 
Java :: why use var in java 
Java :: what isz meaning of EL in jsp 
Java :: Java offer() 
Java :: datapicker java 
Java :: javafx character counter 
Java :: java fx custom cell factory for combo box 
Java :: array erstellen java 
Java :: make a string bean spring xml 
Java :: Create hashmap from another maps java 
Java :: convert xml file to node tree with java 
Java :: convert java code to kotlin online 
Java :: java format zero padded binary 
Java :: java byte array to blob 
Java :: method in java 
Java :: multiple return values in function java 
Java :: synchronized block in java 
Java :: arraylist remove value in java 
Java :: how to change my file into binary data using java 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =