There will be two constructors needed, One with no parameter and other with a string parameter
Interviews34 answers
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?
34 Answers
Rajeev KumarPosted Jun 29, 2023, 3:30 AM EDT
Two. You can create first constructor without parameter and second one constructor with parameter.
sushil kumarPosted Mar 6, 2019, 11:00 PM EST
You need to have two different constructors. One is with parameter and another one without parameter.
Hardik VadherPosted Oct 28, 2017, 5:56 AM EDT
You must Define Two constructor Like this
Class A
{
public A()
{
}
public A(string str)
{
}
}
Nani Veerabhadra KarriPosted Oct 19, 2017, 7:09 AM EDT
you can create a function (no need to declare constructor ) , after it call this method in default constructor ::: :) :)
Amit SwamiPosted Oct 14, 2017, 4:43 AM EDT
1
Rohan KattePosted Oct 13, 2017, 5:21 AM EDT
default constructor is also a parameter less constructor
ex:- class Prashant
{
public Prashant(){}
}
Prashant Kumar SinghPosted Oct 5, 2017, 6:00 AM EDT
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.
Posted Oct 3, 2017, 10:07 PM EDT
You need two constructors
Swatismita BiswalPosted Oct 3, 2017, 3:36 AM EDT
There will be two constructors needed, One with no parameter and other with a string parameter.
Arun kumarPosted Sep 27, 2017, 9:25 AM EDT
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 sivaramanPosted Sep 24, 2017, 6:53 AM EDT
2
Mukesh KumarPosted Sep 20, 2017, 1:16 AM EDT
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 SrivastavaPosted Sep 18, 2017, 4:07 AM EDT
If you create a parameterized contructor you will have to create the default constructor too if you need it.
Deepak SamantarayPosted Sep 14, 2017, 3:13 AM EDT
Only one constructor
Praveen KumarPosted Sep 10, 2017, 9:50 PM EDT
2
Hiren ShahPosted Sep 9, 2017, 6:26 PM EDT
1
chinchu tharayilPosted Sep 7, 2017, 4:12 AM EDT
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
Posted Sep 2, 2017, 5:03 AM EDT
2
Narayanan RamachandranPosted Aug 25, 2017, 9:47 PM EDT
two constructor
Anita SuwalPosted Aug 24, 2017, 5:37 AM EDT
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 vijayPosted Aug 22, 2017, 3:24 AM EDT
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 vijayPosted Aug 22, 2017, 3:23 AM EDT
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 DonthalaPosted Aug 17, 2017, 11:22 PM EDT
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 MPosted Aug 16, 2017, 11:08 PM EDT
2 constructors ,First-parameterised Constructor and Second- public default Constructor
swati bardapurkarPosted Aug 16, 2017, 4:59 AM EDT
You will have to write two constructors, both parameter and non parameter(default) type.
MSUPosted Aug 10, 2017, 4:50 AM EDT
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 KattaPosted Aug 8, 2017, 9:13 PM EDT
Two One the default one and second with the string parameter.
Bhavesh ShahPosted Aug 1, 2017, 10:28 PM EDT
anyone you can do either make two constructor one is default with parameter and second with parameter
or
One constructor with optional Parameter
Gopal SharmaPosted Jul 27, 2017, 10:34 PM EDT
2
ismail aakhilPosted Jul 26, 2017, 7:52 AM EDT
You have to write Two constructor One for Default Constructor, and another constructor with a string parameter
Indranil MukhopadhyayPosted Jul 24, 2017, 7:16 AM EDT
One constructor should be enough. Make the string parameter as optional.
public class TestClass
{
public TestClass(string strTest = null)
{
// Your code
}
}
raghavPosted Jul 23, 2017, 11:09 PM EDT
Write Two constructor
First-Parameterized Constructor and Second- Blank Constructor
Dinesh RajputPosted Jul 17, 2017, 12:38 AM EDT
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.
David MccarterPosted Jul 16, 2017, 8:32 AM EDT










