How do you differentiate between a constructor and normal function?
Nitin Choudhary
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.
constructor initiate the object and function is a method work for initiated object.
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) 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.
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.
Normal Functions are those which we have to call But there is no need to call Constructer
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.
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.
constructor is a special function of class that is always called when we create object of class
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
what is serilization and de-serializaion ? Difference between them?
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
Constructor does not a have return type but function having a return type and it can be return the values one by one
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.
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; } }
functions have return type but constructors dont have return type.
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
.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.
Constructor does not have any return type but member function is a return type.
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.
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.
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).
when youe create a instance do some action is constructor. the object refer to call the method is normal function.
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.
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
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