HOW TO CREATE OBJECT OF CLASS??
1. The operator new is use to create a reference to the class.
2. It allocate's a memory the object of the class.
3. Constructors are used to create Object of class.
-It has same name as that of class.
4. A default constructor is created by the java compiler during run-time,
If the coder doesn't define any.
5. Code:
class Refer{ // class Refer.
int a;
Refer(int a){ // Parameterized Constructor.
System.out.println(a);
}
public static void main(String[]abc){
Refer r = new Refer(10); //passing value to variable a of Contructor.
}
}
6. Constructor is a method which have same name with the class and no return type.
7. Parameterized constructor means a value can passed as argument.
8. ScreenShot:
1. The operator new is use to create a reference to the class.
2. It allocate's a memory the object of the class.
3. Constructors are used to create Object of class.
-It has same name as that of class.
4. A default constructor is created by the java compiler during run-time,
If the coder doesn't define any.
5. Code:
class Refer{ // class Refer.
int a;
Refer(int a){ // Parameterized Constructor.
System.out.println(a);
}
public static void main(String[]abc){
Refer r = new Refer(10); //passing value to variable a of Contructor.
}
}
6. Constructor is a method which have same name with the class and no return type.
7. Parameterized constructor means a value can passed as argument.
8. ScreenShot: