C# Programming - Inheritance - Discussion

Discussion Forum : 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();
        } 
    } 
}
base.fun();
A::fun();
fun();
mybase.fun();
A.fun();
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
10 comments Page 1 of 1.

Mayank said:   1 decade ago
Answer is right

Binay said:   1 decade ago
Can anybody explain?

Radhika said:   1 decade ago
I am not able to understand the solution. I'll be very thankful if anybody can help me in this?

Shashwat kumar said:   1 decade ago
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:   1 decade ago
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:   1 decade ago
For this answer the member should be in derived class.

new public void fun().

Instead of

public void fun().

Laky said:   10 years ago
It gives error like this.

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

Jana said:   10 years ago
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:   7 years ago
"base "is a keyword. It used to only inherited the properties of base class like base.fun();.

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

Post your comments here:

Your comments will be displayed after verification.