ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

What's the class constructor and what's benefits behind it ?

user-image
تم إضافة السؤال من قبل Mahmoud Manaa , Network Engineer , Zain - Kuwait
تاريخ النشر: 2013/09/30
Ahmad Anbari
من قبل Ahmad Anbari , Software System Engineer , Continental Jet Services FZCO

A constructor is a method that is called automatically by the runtime environment every time you create an instance of a class. In other words the runtime environment will use the constructor to create an object instance from the class you specify. 

Mahmoud DEHAINI
من قبل Mahmoud DEHAINI , Software Engineer , Mediatechnix

the constructor will create and manipulate all the field of an object. It can do all the necessary treatment also..... the benefit is the following: ur are not forced to repeat all the manipulation and treatment of field in each time u want to create an object.... the constructor will handle all the necessary work

Zubair Ali
من قبل Zubair Ali , Software Developer III , S&P Global

Class constructors are Class constructors & Benifits behind are the benifits we take out of it :)Note: It seems that questioning module on Bayt.com is far different than the one we have on CodeProject. Make it worthful by asking some real-life issues rather to ask bookish questions regarding which you can get better answered on google.

Lokesh Gajbhiye
من قبل Lokesh Gajbhiye , Software Programmer , Datacomp Web Technologies (India) Pvt. Ltd

A method that do not have a return type and the name of the method is as same as class name are basically called as constructor. Reason behind to define a constructor is to make default implementation.

Constructors are invoked as soon as the class object is instantiated.

Constructors can either be default [without parameters] or Parameterised one.

In object oriented programming, any class should have a class constructor and destructor. There are a lot of benefits. Within the class constructor, you need to assign a default values for any defined variables, also you can assign and allocate a memory for any dynamic defined variables related to this class. The destructor, used to deallocate the allocated assigned dynamic variables. You need to do that for a better system coding security.

A class constructor is a method that executes automatically when creating a object instance. The advantages of using them is that you can preset some atributes of the object when you instance it and perform other operations.

Yameen Mohammed Khan
من قبل Yameen Mohammed Khan , IT Manager , Al Faisal Medical Center

A constructor resembles an instance method with no explicit return types. Constructors often have the same name as the declaring class. They have the task of initializing the object's data members.

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟