C# Programming - Constructors - Discussion
Discussion Forum : Constructors - General Questions (Q.No. 10)
10.
How many times can a constructor be called during lifetime of the object?
Discussion:
8 comments Page 1 of 1.
Nikesh Rathour said:
6 years ago
The static constructor can be called only once in its lifetime whereas non-static constructor or explicit can be called n times if n object is created.
Sidharth said:
7 years ago
@RAHUL SINGH.
There you have declared two object of same class. For each object constructor can be called once only.
There you have declared two object of same class. For each object constructor can be called once only.
Deepak Mishra said:
9 years ago
We are talking about which constructor, Static constructor or instance constructor? Because both have different nature in order to call.
Deepak Mishra said:
9 years ago
Constructor will call n times if we create the instance of the class & times.
Creation of instance is nothing but calling of the constructor. Please verify it.
Creation of instance is nothing but calling of the constructor. Please verify it.
Faizan Sarwar said:
1 decade ago
During the lifetime of any object whether it is parameterized or non- parameterized the constructor is called only once.
Rahul singh said:
1 decade ago
Suppose we call parameterized constructor then we call constructor depend upon the object , how many time object are created that time constructors are called.
Ex:-
cons c = new cons(34,23)
cons d = new cons(24,45)
Here we call parameterized constructor two times..
Ex:-
cons c = new cons(34,23)
cons d = new cons(24,45)
Here we call parameterized constructor two times..
Ramesh Malode said:
1 decade ago
When you create the object of the class default constructor called automatically.
John said:
1 decade ago
Only once because Whenever a class or struct is created, its constructor is called.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers