Qus:-What do you mean by Constructor? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 8

Qus:-What do you mean by Constructor?

19th May 2019, 9:46 AM
Deepika Mourya
Deepika Mourya - avatar
3 Answers
+ 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. 👍🏻👍🏻👍🏻
20th May 2019, 5:57 PM
Tushar
Tushar - avatar
+ 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 } }
19th May 2019, 12:49 PM
Vaishnavi Rajkumar Pawar
+ 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 */
19th May 2019, 9:53 AM
Airree
Airree - avatar