Which of the following statement is invalid with regards to constructor

A) Constructors should have the same name as class name
B) Constructors have to be public so that class can be instantiated
C) Constructors can not be overloaded
Explanation: Constructors can be overloaded with different parameters

Showing Answers 1 - 11 of 11 Answers

hari charagundla

  • Jan 4th, 2006
 

I do not agree with the author, We can have over loaded constructor, taking different parameters. I think B is the answer as a class can have private constructor.Hari

wasim khan

  • Jan 6th, 2006
 

A) Constructors should have the same name as class name
B) Constructors have to be public so that class can be instantiated
C) Constructors can not be overloaded

All is currect........

  Was this answer useful?  Yes

naveentej

  • Jan 8th, 2006
 

I beg ur pardon reg. to my previous comment which turns out to be a foolish one

Ans: C

Guys, the author asks to point out which option is invalid regarding constructors.Option C says that constructors cannot be overloaded which is invalid becoz its possible as the author said.

  Was this answer useful?  Yes

samiksc

  • Jan 9th, 2006
 

Two statements are INVALID:

B -- since constructors can be protected / private. A class with a protected constructor can be instantiated through a derived class. A class with a private constructor can be instantiated through a friend class / friend function.

C -- since constructors can be and very often are overloaded.

Even statement A should be rewritten as follows to make it valid -- Constructors MUST HAVE the same name as class name.

George

  • Aug 11th, 2011
 

C is the correct Answer because constructor can be overloaded..

Code
  1. class A

  2. {

  3.  public A()

  4.  {

  5.   //default constructor

  6.  }

  7.  public A(int x)

  8.  {

  9.   //overloaded constructor

  10.  }

  11. }

  Was this answer useful?  Yes

Deepak kumar

  • Aug 14th, 2011
 

C is the right Answer.
Constructors can be overloaded with multiple parameters.

Code
  1. class Program

  2.     {

  3.         public Program(int a,int b)

  4.         {

  5.             int c;

  6.             c = a + b;

  7.             Console.WriteLine("Total " + c);

  8.         }

  9.          Program(string p, int q)

  10.         {

  11.             Console.WriteLine("Example " + p + q);

  12.         }

  13.         static void Main(string[] args)

  14.         {

  15.             Program obj = new Program(12, 13);

  16.             Program obj1 = new Program("Deepak ", 16);

  17.         }

  18.     }

Simbhu

  • Aug 14th, 2012
 

Ans: A

  Was this answer useful?  Yes

GAURAV GUPTA

  • Aug 25th, 2012
 

C) Constructors can not be overloaded

  Was this answer useful?  Yes

Viky

  • Oct 4th, 2012
 

The correct answer is B: as constructors need not be public we can have private constructors also for instance a singleton object has a private constructor

  Was this answer useful?  Yes

Sunil

  • Sep 24th, 2014
 

All three options are true about constructor.

  Was this answer useful?  Yes

Arun

  • Dec 12th, 2014
 

Option C is invalid, because constructor can be parameterized, hence can be overloaded.

Code
  1. class Mouse

  2. {

  3.     public Mouse()     

  4.     {

  5.         int weight;

  6.         string name;

  7.         weight=-1; name=""

  8.     }

  9.  

  10.     public Mouse(int weight, string name)

  11.     {

  12.         Console.WriteLine("Constructor weight = {0}, name = {1}", weight, name);

  13.     }

  14. }

  15.  

  16. class Program

  17. {

  18.     static void Main()

  19.     {

  20.         Mouse obj1 = new Mouse();

  21.         Mouse obj2 = new Mouse(10, "Sam");

  22.     }

  23. }

  24.  

  25. Output

  26.  

  27. Constructor weight = -1, name =

  28. Constructor weight = 10, name = Sam

  Was this answer useful?  Yes

Saurabh

  • Dec 24th, 2014
 

B is invalid as we can have private constructor in case of Singleton we use the same strategy.

  Was this answer useful?  Yes

Manish

  • Jan 6th, 2015
 

B&C are wrong. B : In case of singleton we create a private constructur for class. A static method in this class calls the constructor nad returns the class instance. C : We can have any number of constructor for a class. Since the name of constructor is same as class multiple constructur is possible only with overloading.

  Was this answer useful?  Yes

S.M.Sadrul Islam Asif

  • Feb 5th, 2015
 

B,We can have private constructor.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions