Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

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);
  }
}
Source by softhunt.net #
 
PREVIOUS NEXT
Tagged: #Java #public #constructors
ADD COMMENT
Topic
Name
1+3 =