GeekInterview.com
Series: Subject: Topic:
Question: 185 of 460

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
Asked by: Interview Candidate | Asked on: Jan 1st, 2006
Showing Answers 1 - 16 of 16 Answers
hari charagundla

Answered On : 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

Yes  2 Users have rated as useful.
  
Login to rate this answer.
wasim khan

Answered On : 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........

  
Login to rate this answer.
naveentej

Answered On : Jan 7th, 2006

View all answers by naveentej

Constructors can be private thats true

Constructors can be overloaded with multiple parameters

So answer is B

  
Login to rate this answer.
naveentej

Answered On : Jan 8th, 2006

View all answers by naveentej

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.

  
Login to rate this answer.
samiksc

Answered On : Jan 9th, 2006

View all answers by samiksc

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.

Yes  1 User has rated as useful.
  
Login to rate this answer.
George

Answered On : 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. }

  
Login to rate this answer.
Deepak kumar

Answered On : 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.     }

Yes  1 User has rated as useful.
  
Login to rate this answer.
Sivavt

Answered On : Apr 2nd, 2012

View all answers by Sivavt

(B) & (C) are invalid.

  
Login to rate this answer.
govil

Answered On : Jul 11th, 2012

View all answers by govil

(b)

  
Login to rate this answer.
Simbhu

Answered On : Aug 14th, 2012

Ans: A

  
Login to rate this answer.
sureshda

Answered On : Aug 20th, 2012

View all answers by sureshda

C)

  
Login to rate this answer.
GAURAV GUPTA

Answered On : Aug 25th, 2012

C) Constructors can not be overloaded

  
Login to rate this answer.
minoli

Answered On : Sep 16th, 2012

View all answers by minoli

C) Constructors can not be overloaded

  
Login to rate this answer.
randheer

Answered On : Sep 26th, 2012

View all answers by randheer

c. As constructors can be overloaded.

  
Login to rate this answer.
Viky

Answered On : 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

  
Login to rate this answer.

all the three statements are true...

  
Login to rate this answer.

Give your answer:

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

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Ads

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.