57
Reply

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?

David Mccarter

David Mccarter

Jul 16, 2017
3.8k
9

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

    raghav
    July 24, 2017
    12

    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.

    Sneha Mallick
    October 04, 2017
    3

    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.

    Murthy Donthala
    August 18, 2017
    3

    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.

    Deepan M
    August 17, 2017
    3

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

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

    Dinesh Rajput
    July 17, 2017
    3

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

    Hardik Vadher
    October 28, 2017
    2

    2

    Hiren Shah
    September 09, 2017
    2

    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=""){ }}

    Ankur vijay
    August 22, 2017
    2

    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=""){ }}

    Ankur vijay
    August 22, 2017
    2

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

    Nani Veerabhadra Karri
    October 19, 2017
    1

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

    Amit Swami
    October 14, 2017
    1

    1

    Rohan Katte
    October 13, 2017
    1

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

    Prashant Singh
    October 05, 2017
    1

    You need two constructors

    Swatismita Biswal
    October 03, 2017
    1

    You need two constructors

    Swatismita Biswal
    October 03, 2017
    1

    You need two constructors

    Swatismita Biswal
    October 03, 2017
    1

    You need two constructors

    Swatismita Biswal
    October 03, 2017
    1

    You need two constructors

    Swatismita Biswal
    October 03, 2017
    1

    You need two constructors

    Swatismita Biswal
    October 03, 2017
    1

    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.

    vijayan sivaraman
    September 24, 2017
    1

    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.

    vijayan sivaraman
    September 24, 2017
    1

    2

    Mukesh Kumar
    September 20, 2017
    1

    2

    Mukesh Kumar
    September 20, 2017
    1

    2

    Mukesh Kumar
    September 20, 2017
    1

    2

    Mukesh Kumar
    September 20, 2017
    1

    2

    Mukesh Kumar
    September 20, 2017
    1

    2

    Mukesh Kumar
    September 20, 2017
    1

    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.

    Amar Srivastava
    September 18, 2017
    1

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

    Deepak Samantaray
    September 14, 2017
    1

    Only one constructor

    Praveen
    September 11, 2017
    1

    1

    chinchu tharayil
    September 07, 2017
    1

    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

    karan singh
    September 02, 2017
    1

    2 construct er

    Mukesh Kumar
    August 31, 2017
    1

    2

    Mukesh Kumar
    August 29, 2017
    1

    2

    Narayanan Ramachandran
    August 26, 2017
    1

    two constructor

    Anita Suwal
    August 24, 2017
    1

    2

    Mukesh Kumar
    August 23, 2017
    1

    You need two constructors

    Swatismita Biswal
    October 03, 2017
    0

    You need two constructors

    Swatismita Biswal
    October 03, 2017
    0

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

    Arun kumar
    September 27, 2017
    0

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

    Arun kumar
    September 27, 2017
    0

    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.

    vijayan sivaraman
    September 24, 2017
    0

    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.

    vijayan sivaraman
    September 24, 2017
    0

    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.

    vijayan sivaraman
    September 24, 2017
    0

    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.

    vijayan sivaraman
    September 24, 2017
    0

    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.

    vijayan sivaraman
    September 24, 2017
    0

    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.

    vijayan sivaraman
    September 24, 2017
    0

    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.

    vijayan sivaraman
    September 24, 2017
    0

    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=""){ }}

    Ankur vijay
    August 22, 2017
    0

    ergeg

    Ankur vijay
    August 22, 2017
    0

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

    swati bardapurkar
    August 16, 2017
    0

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

    MSU
    August 10, 2017
    0

    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.

    Swetha Katta
    August 09, 2017
    0

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

    Bhavesh Shah
    August 02, 2017
    0

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

    Gopal Sharma
    July 28, 2017
    0

    2

    ismail aakhil
    July 26, 2017
    0