Log In
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
0 votes
why did constructor's name is same as class name and it has no return type
in Object Oriented Programming 103 views
Constructors are used for object instantiation. It is like initializing the object created with the given values. You don't expect it to return anything. It just sets values (does groundwork specified in the constructor). It returns nothing. Not even void

Constructor's name is same as the class name so that the compiler can distinguish it from other functions in that class.

agreed with @gauravkc just would like to rephrase "initializing the object created with the given values" as initializing the fields of the object with given values, after a constructor is invoked a space is created  in memory for the object and initializes its fields

Please log in or register to answer this question.

Related questions

0 votes
1 answer
Which of the following is not correct (in C++)? 1) Class templates and function templates are instantiated in the same way. 2) Class templates differ from function templates in the way they are initiated. 3) Class templates is initiated by defining an object using the template argument. 4) Class templates are generally used for storage classes.
asked Nov 9, 2017 in Object Oriented Programming Devwritt 1.4k views
0 votes
1 answer
Which of the following is true? (A) A static member of a class cannot be inherited by its derived class. (B) A static member of a class can be initialized only within the class it is a member of. (C) A static member of a class can be ... Since static member of a class is actually a global element, it does not require a class/object qualifier to access it independently of class/object.
asked Sep 27, 2017 in Object Oriented Programming rishu_darkshadow 311 views
5 votes
2 answers
Consider the class of object oriented languages. Which of the following is true? Pascal is an object oriented language. Object oriented languages require heap management. Object oriented languages cannot be implemented in language C. Object oriented languages are more powerful than declarative programming languages. Parallelism cannot be realized in object oriented languages.
asked Oct 26, 2015 in Object Oriented Programming makhdoom ghaya 389 views
5 votes
2 answers
Match the following concepts and their best possible descriptions. Concept Description i. overloading a. allows to define a class to have properties of another class ii. friend b. defining a set of similar functions iii. constructor c. used in dereferencing iv. protected d. used to give a non-member function access to the ... i-c, ii-f, iii-h, iv-a, v-g, vi-d i-b, ii-e, iii-c, iv-f, v-g, vi-s
asked Nov 1, 2014 in Object Oriented Programming Ishrat Jahan 924 views