+ 8
Qus:-What do you mean by Constructor?
3 ответов
+ 13
Constructor in c++ is a member function of a class having same name as of class without any datatype . It is used to initialize the data members of the class and automatically invoke when an object of the class is created.
👍🏻👍🏻👍🏻
+ 3
A constructor is a specialized method for initializing objects.
Name of the constructor is same as that of its class name.
Whenever an object of its associated class is created, the constructor is invoked automatically.
Example:
class Test //class name is Test
{
Test() // Constructor
{
// body of constructor
}
}
+ 1
A construnctor is used when creating objects. For exapmple:
class Student {
public static void Student(String name, int age, double average) {
this.name = name;
this.age = age;
this.average = average;
}
}
Student s1 = new Student("John", 16, 3.00);
System.out.println(s1.name + " " + s1.age + " " + s1.average);
/*
John 16 3.00
*/