What are the keywords used to pass parameters to
the base class and how do I invoke other constructors.

Answers were Sorted based on User's Feedback



What are the keywords used to pass parameters to the base class and how do I invoke other constr..

Answer / radhika

using base keyword we can pass parameters to the baseclass.
When an instance of the DerivedClass is created.The default
constructor in BaseClass is first invoked followed by the
DerivedClass . However, you
can choose which constructor you want to invoke in
BaseClass by using the base keyword in the
default constructor in DerivedClass , like this:

public class BaseClass
{
//---default constructor---
public BaseClass()
{
Console.WriteLine(“Default constructor in BaseClass”);
}
//---parameterized constructor---
public BaseClass(int x)
{
Console.WriteLine(“Parameterized Constructor in BaseClass”);
}
}

public class DerivedClass : BaseClass
{
//---default constructor---
public DerivedClass(): base(4)
{
Console.WriteLine(“Constructor in DerivedClass”);
}
}

Is This Answer Correct ?    5 Yes 0 No

What are the keywords used to pass parameters to the base class and how do I invoke other constr..

Answer / varish

Class Base
{
Base(int i)
{
}
}
class child
{
child(int i):base(i)
{
}
}

Is This Answer Correct ?    5 Yes 1 No

What are the keywords used to pass parameters to the base class and how do I invoke other constr..

Answer / ram

Class Base
{
Base(int i)
{
}
}
class child
{
child(int i):Base(i)
{
}
}

Is This Answer Correct ?    2 Yes 0 No

Post New Answer

More C Sharp Interview Questions

What benefit do you get from using a primary interop assembly (pia)?

0 Answers  


How do you declare a variable in c#?

0 Answers  


can we create an empty interface with no definitions? If so, how it should be called in the class?

3 Answers   IBM,


what is ment by Unboxing?

3 Answers  


Are c# destructors the same as c++ destructors?

0 Answers  






what are delegates? How you used then in your project?

10 Answers   Hawk Eye, IndiaTimes, Kanbay,


How can I develop an application that automatically updates itself from the web?

0 Answers  


What is the difference between const and static read-only?

0 Answers  


How do you specify a custom attribute for the entire assembly (rather than for a class)?

0 Answers  


What is a delegate? Explain.

0 Answers  


Is c# an array?

0 Answers  


What are the benefits of using the aggregate method in linq?

0 Answers  


Categories