Interviews29 answers
How do you differentiate between a constructor and normal function?
29 Answers
1) Function has to be invoked. Constructor automatically gets invoked.
2) Function has return type. Constructor has no return type.
3) Function is method work for initiated object. Constructor initiates the object.
Shalini PuriPosted Dec 2, 2017, 9:08 PM EST
Normal Functions are those which we have to call
But there is no need to call Constructer
Mukesh KumarPosted Aug 28, 2017, 10:35 PM EDT
constructor doesn't have a return type where as a function has.
constructor is like entry point to access the members of a class. As soon as we create the object constructor gets called where as we have to explicitly call methods either by object or class itself depending upon its nature.
Anil Kumar MurmuPosted Feb 4, 2016, 11:54 PM EST
constructor function has same name as class from its belong i.e. name of the class and constructor function should be same on the other hand normal function has not such implication.
Barkha GuptaPosted Jan 22, 2016, 8:45 PM EST
constructor is a special function of class that is always called when we create object of class
Ayyaz AhmadPosted Dec 19, 2015, 2:59 AM EST
three main point in constructor
=>it should be public,
=>no return type
=>class name and constructor same
in Normal Function
=>return type ma be ya no .
=>it's may be public,private etc
=>any thing function name
ahmed ghaniiPosted Nov 17, 2015, 3:47 AM EST
what is serilization and de-serializaion ? Difference between them?
suraj patilPosted Oct 3, 2015, 11:15 AM EDT
construtor is a special type of method which will have the same name as class name
and it constructor main purpose is to initialize the values
method is a member of the class which defines some functionality
and it should have some return type
Srinivas PabballaPosted Aug 28, 2015, 1:28 AM EDT
Constructor does not a have return type but function having a return type and it can be return the values one by one
Mahalakshmi MeganathanPosted Aug 7, 2015, 3:20 AM EDT
A constructor is a special kind of method from where execution starts in side a class. Where as a function is a normal kind of method & used to provide some functionality.
A function may or may not return value where as a constructor must not return value.
Sujeet SumanPosted Jun 18, 2015, 1:50 AM EDT
constructor does'n have a return type, the name of constructor should be the same as the class name
and functions can have return type and the name is user defined.
constructor initiate the object and function is a method work for initiated object.
Rahul PrajapatPosted May 27, 2015, 2:15 AM EDT
A constructor is a special function that is used to begin an object of a class
One can declare hole or to begin one or all the properties of a class
Not it returns value, it is named with the name of the Class
In the class several constructor can exist
For example in c#:
public class Customer
{
private int number;
private string name;
public Customer(){}
public Customer()
{
this.number=4;
this.name="Frank";
}
public Customer(int num1, int num2)
{
this.number=num1+num2;
}
public Customer(int number, string name)
{
this.number=number;
this.name=name;
}
}
Frank Núñez RodríguezPosted May 14, 2015, 6:36 AM EDT
constructor does'n have a return type, the name of constructor should be the same as the class name
and functions can have return type and the name is user defined
Safayat ZisanPosted Apr 18, 2015, 2:29 PM EDT
.Constructor are used to initialize the state of object,where as method is expose the behaviour of object.
2.Constructor must not have return type where as method must have return type.
3.Constructor name same as the class name where as method may or may not the same class name.
4.Constructor invoke implicitly where as method invoke explicitly.
5.Constructor compiler provide default constructor where as method compiler does't provide.
Munesh SharmaPosted Apr 15, 2015, 10:53 PM EDT
Constructor does not have any return type but member function is a return type.
Santhakumar MunuswamyPosted Apr 14, 2015, 7:20 PM EDT
constructor can be excute automatically whenever objects created.in the constructor we can initialize the values of the variables.
Member function can excute when we call the function through the object.
Posted Apr 14, 2015, 7:00 PM EDT
A constructor is a method of a class which have to return type and name of the constructor is same as the name of the class.It will only called when we instantiate class objects. You can not explicitly call a constructor.
Satyam VermaPosted Apr 11, 2015, 9:06 PM EDT
A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself, has no return type, and is invoked using the new operator. An ordinary member function has its own name, a return type (which may be void), and is invoked using the dot operator.
Munesh SharmaPosted Mar 29, 2015, 8:08 PM EDT
A constructor is a member function of a class that is used to create objects and assign values to property that is need in start of that class. It has the same name as the class itself, has no return type, and is invoked using the new operator. An ordinary member function has its own name, a return type (which may be void).
Akhil GargPosted Mar 28, 2015, 9:01 PM EDT
when youe create a instance do some action is constructor. the object refer to call the method is normal function.
CHANDRAN KANDANPosted Mar 27, 2015, 3:50 AM EDT
Other Member of Class like Method & variables are work on instance of that class.for creating instance of that class some thing is required.so constructor is do that thing.it will allocate memory give instance of class & allow to access other member of class.without instance other method of class can't access.
Ganesh SarafPosted Mar 11, 2015, 11:35 PM EDT
A constructor allocates the objects into the memory, depending on the type of object; class or struct etc, it should be allocated on the heap or stack. Where as a function is any function that can be executed upon an object. You can have many functions and point to be noted is that a constructor is also a "function" with a void return-type and possibly zero or many parameters; used to initialize the object.
Afzaal Ahmad ZeeshanPosted Mar 8, 2015, 3:08 PM EDT
constructor initiate the object and function is a method work for initiated object.
Navin KumarPosted Feb 27, 2015, 4:59 AM EST
constructor initiate the object and function is a method work for initiated object.
Navin KumarPosted Feb 27, 2015, 4:59 AM EST
constructor initiate the object and function is a method work for initiated object.
Navin KumarPosted Feb 27, 2015, 4:59 AM EST
If we use a readonly string in class then constructor can change the value of string but a normal function can not change it's value
Pankaj Kumar ChoudharyPosted Feb 20, 2015, 3:17 AM EST
Constructor is a function which called automatically
when a object of class is initialized,
But a method is called when its explicit called by object
constructor not have any return type
Normal Function has.
use of constructors is, we can feed the default values which we need to pass to that class
public class Class1
{
private int a, b;
public Class1(int a, int b) //Constructors with parameter
{
this.a = a;
this.b = b;
}
public Class1() //Constructors without parameter
{
}
}
Main()
{
Class1 cls = new Class1();
Class1 cls1 = new Class1(2, 3); // Here we can feed Default values to a class
}
A constructor can be used to set default values
saravanagopi sPosted Feb 18, 2015, 9:56 PM EST
A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself, has no return type, and is invoked using the new operator. An ordinary member function has its own name, a return type (which may be void), and is invoked using the dot operator.
Nitin ChoudharyPosted Feb 11, 2015, 3:24 AM EST
















