Search Placementyogi.com
 

C# Inheritance - Basic Objective Questions

1

Inheritance is one of the pillar of Object-Oriented-Programming (OOP).

A. True
B. False
See Answer & Explanation Lets Discuss
Correct answer is : A
Explanation

Inheritance, Encapsulation and Polymorphism are three pillars of OOP.

 
2

Which of the following statements are true regarding Inheritance? (Multiple Choice)

A.

Derived class can access protected and public members of base class.

B.

Derived class can use the functionality of base class.

C.

Derived class can implement new functionality other than base class.

D.

Derived class functions can override functions of base class.

See Answer & Explanation Lets Discuss
Correct answer is : A,B,C,D
Explanation

No explanation available. Let's Discuss

 
3

The following C# program executes without any error?

using System;
namespace PlacementYogi
{
    class BaseClass
    {
        private int a = 10;
        protected int b = 20;
        public int c = 30;
    }
    class DerivedClass : BaseClass
    {
        int d = 40;
        public void fun()
        {
            Console.WriteLine(a +" "+ b +" "+ c +" "+ d);
        }
    }
    class Testing
    {
        public static void Main(String[] args)
        {
            DerivedClass obj = new DerivedClass();
            obj.fun();
        }
    }
}
A. True
B. False
See Answer & Explanation Lets Discuss
Correct answer is : B
Explanation
Compiler throws the below error:
'PlacementYogi.BaseClass.a' is inaccessible due to its protection level
Note: A private member (here a) of base class cannot be accessed from a derived class (DerivedClass).
 
4

Which of the following statements are true about the C# program given below? (Multiple Choice)

using System;
namespace PlacementYogi
{
    class BaseClass
    {
        protected int x;
        public BaseClass()
        {
            x = 1;
        }
    }
    class DerivedClass : BaseClass
    {
	int y = 1;
        public void Calculate()
        {
            x = x + 1;
        }
        public void display()
        {
            Console.WriteLine(x);
        }
    }
    class Testing
    {
        static void Main(string[] args)
        {
            DerivedClass obj = new DerivedClass();
            obj.Calculate();
            obj.display();
        }
    }
}
A.

x must be public in order to be accessed by DerivedClass.

B.

The output of this program is 2.

C.

Constructor of derived class DerivedClass is called first.

D.

BaseClass constructor cannot be inherited from derivedClass.

See Answer & Explanation Lets Discuss
Correct answer is : B,D
Explanation

No explanation available. Let's Discuss

 
5

Which of the following statements are true regarding inheritance in C#? (Multiple Choice)

A.

Multiple level inheritance is allowed in C#.

B.

Base class can access the members of its derived class.

C.

Multiple inheritance is allowed in C#.

D.

A class can be derived from a base class which is present in an assembly file.

See Answer & Explanation Lets Discuss
Correct answer is : A,D
Explanation

Multiple Level Inheritance: A class which is derived from a base class and base class is derived from another base class etc.

Multiple Inheritance: A class derived from different base classes. It's not allowed in C#.

 
 

Banner to LogicGuns.com

Hide Page Information

C# Inheritance - Basic Objective Questions and Answers with Explanation

Here you can find basic level C# inheritance interview questions with answers and explanation.

Why Inheritance in C#?

In this section you can learn and practice different types of basic level questions with answers on inheritance to improve your skills in order to face the interviews, competitive examinations and various entrance tests with full confidence.

Where can I get C# Inheritance Basic Questions and Answers with Explanation?

PlacementYogi provides you lots of fully solved basic level inheritance questions and answers with explanation. Fully solved examples with detailed answer description, explanation are given and it would be easy to understand. All students, freshers can download Operators quiz questions with answers as PDF files and eBooks.

Where can I get Basic Level C# Inheritance Interview Questions and Answers (objective type, multiple choice)?

Here you can find objective type basic inheritance questions and answers for interview and entrance examination. Multiple choice and TRUE or FALSE type and YES or NO type questions are also provided.