David Mccarter
A class provides a default constructor for me. I write a constructor that takes a string as a parameter, but want to keep the no parameter constructor. How many constructors should I write?
By David Mccarter in .NET on Jul 16 2017
  • raghav
    Jul, 2017 24

    One constructor should be enough. Make the string parameter as optional. public class TestClass{public TestClass(string strTest = null){// Your code}}

    • 15
  • David Mccarter
    Jul, 2017 16

    Two. Once you write at least one constructor, The compiler cancels the freebie constructor, and now you have to write one yourself, even if there’s no implementation in it.

    • 14
  • Sneha Mallick
    Oct, 2017 4

    Whenever a class is created a constructor is called, and this default constructor is invoked when object of the class is created but Once we create a parameterized constructor, the class no more provides the default constructor. Therefore, in this case, we need to write two constructor, one with a string as parameter and another without parameter.

    • 3
  • Indranil Mukhopadhyay
    Jul, 2017 24

    You have to write Two constructor One for Default Constructor, and another constructor with a string parameter

    • 3
  • Hiren Shah
    Sep, 2017 9

    2

    • 1
  • Ankur vijay
    Aug, 2017 22

    One constructor possible developers class Program{static void Main(string[] args){Employee p = new Employee("effewdf");Employee pe = new Employee();}}public class Employee{public Employee(string s=""){ }}

    • 1
  • Murthy Donthala
    Aug, 2017 18

    According to oops, by default a class will have default constructor until you didn't create any parameterized. If u create any parameterized you need to create zero perameterized constructor explicitly.

    • 1
  • Deepan M
    Aug, 2017 17

    It depends on your usage. If you want some values to be initialized while creating an object for a class. Then you should consider parameterized constructor or if you want that initialization to be optional then you should have both default and parameterized constructor in your class.

    • 1
  • Dinesh Rajput
    Jul, 2017 17

    Write Two constructor First-Parameterized Constructor and Second- Blank Constructor

    • 1
  • Rajeev Kumar
    Jun, 2023 29

    There will be two constructors needed, One with no parameter and other with a string parameter

    • 0
  • sushil kumar
    Mar, 2019 7

    Two. You can create first constructor without parameter and second one constructor with parameter.

    • 0
  • Hardik Vadher
    Oct, 2017 28

    You need to have two different constructors. One is with parameter and another one without parameter.

    • 0
  • Nani Veerabhadra Karri
    Oct, 2017 19

    You must Define Two constructor Like this Class A {public A(){}public A(string str){} }

    • 0
  • Amit Swami
    Oct, 2017 14

    you can create a function (no need to declare constructor ) , after it call this method in default constructor ::: :) :)

    • 0
  • Rohan Katte
    Oct, 2017 13

    1

    • 0
  • Prashant Kumar Singh
    Oct, 2017 5

    default constructor is also a parameter less constructor ex:- class Prashant { public Prashant(){} }

    • 0
  • Swatismita Biswal
    Oct, 2017 3

    You need two constructors

    • 0
  • Arun kumar
    Sep, 2017 27

    There will be two constructors needed, One with no parameter and other with a string parameter.

    • 0
  • vijayan sivaraman
    Sep, 2017 24

    Two. I think this is handled by the compiler. If you open the .net assembly in ILDASM you will see the default constructor, even if it is not in the code. If you define a parameterized constructor the default constructor will not bee seen.Actually when you define the class (non static), the compiler provides this feature thinking that you will be just creating an instance. And if you want any specific operation to perform you surely will be having your own constructor.

    • 0
  • Mukesh Kumar
    Sep, 2017 20

    2

    • 0
  • Amar Srivastava
    Sep, 2017 18

    In the case you are taking about You have to write at least two constructor because once you write any constructor with any params then compiler will search for the default one. Else if you dont create a parameterize one you don't need to create a default constructor.

    • 0
  • Deepak Samantaray
    Sep, 2017 14

    If you create a parameterized contructor you will have to create the default constructor too if you need it.

    • 0
  • Praveen Kumar
    Sep, 2017 11

    Only one constructor

    • 0
  • chinchu tharayil
    Sep, 2017 7

    1

    • 0
  • karan singh
    Sep, 2017 2

    HP,IBM,Tandberg Tape drive Repair and Backup company Pertho Engineers is a growing LTO Tape Drive repair and backup service provider company in india.We at Pertho Engineers also provide you LTO-3, LTO-4, LTO-5, LTO-6, LTO-7 Tape Drive repair and backup services in UAE. Pertho Engineers provides all company LTO Tape Drive repair and backup services in UAE. The leading companies whom repair and backup services are HP, IBM, Certance LTO, Quantum LTO, Tandberg LTO, Quantum DLT, Quantum VS80 VS160, Quantum SDLT, HP DAT DDS, Sony DAT DDS. Contact us 9871495530. http://serverntapedrive.com/hp-ibm-tandberg-tape-drive-repair-backup-company/http://i1152.photobucket.com/albums/p494/serverntapedrive/HPIBMTandberg%20Tape%20drive%20Repair%20and%20Backup%20company_zpsud12jltc.jpg

    • 0
  • Narayanan Ramachandran
    Aug, 2017 26

    2

    • 0
  • Anita Suwal
    Aug, 2017 24

    two constructor

    • 0
  • Ankur vijay
    Aug, 2017 22

    One is sufficient.class Program{static void Main(string[] args){Employee p = new Employee("effewdf");Employee pe = new Employee();}}public class Employee{public Employee(string s=""){ }}

    • 0
  • swati bardapurkar
    Aug, 2017 16

    2 constructors ,First-parameterised Constructor and Second- public default Constructor

    • 0
  • MSU
    Aug, 2017 10

    You will have to write two constructors, both parameter and non parameter(default) type.

    • 0
  • Swetha Katta
    Aug, 2017 9

    Two constructors u hv to define one is by passing String as a parameter, and one more u hv to declare default constructor without arguments bcz once u define any constructor Thn compiler won't provide default constructor so the scenario , wen u want to declare parameterized constructor n default constructor as well Thn u hv to do it explicitly.

    • 0
  • Bhavesh Shah
    Aug, 2017 2

    Two One the default one and second with the string parameter.

    • 0
  • Gopal Sharma
    Jul, 2017 28

    anyone you can do either make two constructor one is default with parameter and second with parameteror One constructor with optional Parameter

    • 0
  • ismail aakhil
    Jul, 2017 26

    2

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS