// CONSTRUCTOR
public class Class1 {
// Object is made by calling the constructor
//Object is calling by creating the constructor
//Constructor use all four ACCESS MODIFIERS
public Class1() {
System.out.println("This is the default constructor");
System.out.println(" Creating the object by calling the constructor\n");
}
public Class1(String name) {
System.out.println("This is the constructor with String Args");
}
public static void main(String[] args) {
Class1 c1 = new Class1();
// new Class1() -- This means the constructor Call means
// the upper one constructor
Class1 c2 = new Class1("nanana");
// new Class2(String name) -- This means the constructor
// Call means the lower one constructor
}
}
No comments:
Post a Comment