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

Why does dllimport not work for me?

0 Answers  


What is immutable in C#?

0 Answers   SwanSoft Technologies,


Can we inherit sealed class in c#?

0 Answers  


How do I create a new form in c#?

0 Answers  


What are c# i/o classes?

0 Answers  






Is c# 8 released?

0 Answers  


What is float in unity?

0 Answers  


Why do we need reflection in c#?

0 Answers  


What is a value type in c#?

0 Answers  


What is a string c#?

0 Answers  


What is event delegate in c#?

0 Answers  


Explain dataset.acceptchanges method in .net?

0 Answers  


Categories