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