Nitin Choudhary
How do you differentiate between a constructor and normal function?
By Nitin Choudhary in OOP/OOD on Feb 11 2015
  • Shalini Puri
    Dec, 2017 3

    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.

    • 4
  • Ganesh Saraf
    Mar, 2015 12

    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.

    • 3
  • Navin Kumar
    Feb, 2015 27

    constructor initiate the object and function is a method work for initiated object.

    • 3
  • Nitin Choudhary
    Feb, 2015 11

    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.

    • 3
  • Sujeet Suman
    Jun, 2015 18

    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.

    • 2
  • Mukesh Kumar
    Aug, 2017 29

    Normal Functions are those which we have to call But there is no need to call Constructer

    • 1
  • Anil Kumar Murmu
    Feb, 2016 5

    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.

    • 1
  • Barkha Gupta
    Jan, 2016 23

    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.

    • 1
  • Ayyaz Ahmad
    Dec, 2015 19

    constructor is a special function of class that is always called when we create object of class

    • 1
  • ahmed ghanii
    Nov, 2015 17

    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

    • 1
  • suraj patil
    Oct, 2015 3

    what is serilization and de-serializaion ? Difference between them?

    • 1
  • Srinivas Pabballa
    Aug, 2015 28

    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

    • 1
  • Mahalakshmi Meganathan
    Aug, 2015 7

    Constructor does not a have return type but function having a return type and it can be return the values one by one

    • 1
  • Rahul Prajapat
    May, 2015 27

    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.

    • 1
  • Frank Núñez Rodríguez
    May, 2015 14

    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; } }

    • 1
  • Kml Surani
    May, 2015 8

    functions have return type but constructors dont have return type.

    • 1
  • Safayat Zisan
    Apr, 2015 18

    constructor does'n have a return type, the name of constructor should be the same as the class nameand functions can have return type and the name is user defined

    • 1
  • Munesh Sharma
    Apr, 2015 16

    .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.

    • 1
  • Santhakumar Munuswamy
    Apr, 2015 14

    Constructor does not have any return type but member function is a return type.

    • 1
  • Kml Surani
    Apr, 2015 14

    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.

    • 1
  • Satyam Verma
    Apr, 2015 12

    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.

    • 1
  • Munesh Sharma
    Mar, 2015 30

    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.

    • 1
  • Akhil Garg
    Mar, 2015 29

    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).

    • 1
  • CHANDRAN KANDAN
    Mar, 2015 27

    when youe create a instance do some action is constructor. the object refer to call the method is normal function.

    • 1
  • Afzaal Ahmad Zeeshan
    Mar, 2015 8

    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.

    • 1
  • Navin Kumar
    Feb, 2015 27

    constructor initiate the object and function is a method work for initiated object.

    • 1
  • Navin Kumar
    Feb, 2015 27

    constructor initiate the object and function is a method work for initiated object.

    • 1
  • Pankaj  Kumar Choudhary
    Feb, 2015 20

    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

    • 1
  • saravanagopi s
    Feb, 2015 19

    Constructor is a function which called automatically when a object of class is initialized, But a method is called when its explicit called by objectconstructor 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 classpublic 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

    • 1


Most Popular Job Functions


MOST LIKED QUESTIONS