C# Programming - Inheritance - Discussion

Discussion :: Inheritance - General Questions (Q.No.5)

5. 

Which statement will you add in the function fun() of class B, if it is to produce the output "Welcome to IndiaBIX.com!"?

namespace IndiabixConsoleApplication
{ 
    class A
    {
        public void fun()
        {
            Console.Write("Welcome");
        } 
    } 
    class B: A
    {
        public void fun()
        {
            // [*** Add statement here ***]
            Console.WriteLine(" to IndiaBIX.com!");
        } 
    } 
    class MyProgram
    { 
        static void Main (string[ ] args)
        { 
            B b = new B(); 
            b.fun();
        } 
    } 
}

[A]. base.fun();
[B]. A::fun();
[C]. fun();
[D]. mybase.fun();
[E]. A.fun();

Answer: Option A

Explanation:

No answer description available for this question.

Mayank said: (Jun 13, 2011)  
Answer is right

Binay said: (Feb 5, 2012)  
Can anybody explain?

Radhika said: (May 1, 2012)  
I am not able to understand the solution. I'll be very thankful if anybody can help me in this?

Shashwat Kumar said: (Jul 13, 2012)  
Option A is right because to access public and protected members of base class can be accessed in derived class by using "base" keyword. That's why option A is correct.

Gaurav Porwal said: (Jan 15, 2013)  
In derived class, we are hiding the base class function fun() , so to call base class function it should be called from the derived class function. Hence, option A is right.

Binita said: (Nov 26, 2013)  
For this answer the member should be in derived class.

new public void fun().

Instead of

public void fun().

Laky said: (Jul 31, 2014)  
It gives error like this.

"Keyword 'base' is not available in a static method".

Jana said: (Aug 13, 2014)  
If you implemented the inheritance, You can get the base class properties and methods into derived class.

So, we need to call the base class method to get this output.

To get the base class properties and methods, you need to call method by base class object Base.

So the line of code to get required o/p is base.fun();

Vishnu said: (Jan 25, 2017)  
"base "is a keyword. It used to only inherited the properties of base class like base.fun();.

Kapil Gupta said: (Nov 7, 2017)  
class B: A
{
public void fun()
{
// [*** Add statement here ***]
base.fun();
Console.WriteLine(" to IndiaBIX.com!");
}
}

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.