adplus-dvertising

Welcome to the Interfaces,Inheritance and Polymorphism MCQs Page

Dive deep into the fascinating world of Interfaces,Inheritance and Polymorphism with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Interfaces,Inheritance and Polymorphism, a crucial aspect of C# Programming. In this section, you will encounter a diverse range of MCQs that cover various aspects of Interfaces,Inheritance and Polymorphism, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within C# Programming.

frame-decoration

Check out the MCQs below to embark on an enriching journey through Interfaces,Inheritance and Polymorphism. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of C# Programming.

Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Interfaces,Inheritance and Polymorphism. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

Interfaces,Inheritance and Polymorphism MCQs | Page 2 of 20

Explore more Topics under C# Programming

Q11.
Which of the following statements are correct about an interface used in C#.NET?

1. An interface can contain properties, methods and events.
2. The keyword must implement forces implementation of an interface.
3. Interfaces can be overloaded.
4. Interfaces can be implemented by a class or a struct.
5. Enhanced implementations of an interface can be developed without breaking existing code.
Discuss
Answer: (b).1, 4, 5
Q12.
Which of the following can implement an interface?

1. Data
2. Class
3. Enum
4. Structure
5. Namespace
Discuss
Answer: (b).2, 4
Q13.
Which of the following statements is correct about the C#.NET code snippet given below?

interface IMyInterface 
{
    void fun1(); 
    void fun2();
}
class MyClass: IMyInterface
{ 
    private int i; 
    void IMyInterface.fun1()
    { 
        // Some code
    } 
}
Discuss
Answer: (d).The compiler will report an error since the interface IMyInterface is only partially implemented.
Q14.
Which of the following statements is correct about the C#.NET code snippet given below?

interface IPerson
{ 
    String FirstName
    { 
        get; 
        set;
    }
    String LastName
    {
        get; 
        set;
    }
    void Print(); 
    void Stock(); 
    int Fun(); 
}
Discuss
Answer: (b).This is a perfectly workable interface.
Discuss
Answer: (a).class Employee : IPerson
{
private String str;
public String FirstName
{
get
{
return str;
}
set
{
str = value;
}
}
}
Q16.
Which of the following can be facilitated by the Inheritance mechanism?

1. Use the existing functionality of base class.
2. Overrride the existing functionality of base class.
3. Implement new functionality in the derived class.
4. Implement polymorphic behaviour.
5. Implement containership.
Discuss
Answer: (a).1, 2, 3
Q17.
Which of the following statements should be added to the subroutine fun( ) if the C#.NET code snippet given below is to output 9 13?

class BaseClass
{
    protected int i = 13;
}
class Derived: BaseClass
{
    int i = 9; 
    public void fun()
    {
        // [*** Add statement here ***]
    } 
}
Discuss
Answer: (b).Console.WriteLine(i + " " + base.i);
Q18.
Which of the following statements are correct about the C#.NET code snippet given below?

1. count should be declared as public if it is to become available in the inheritance chain.
2. count should be declared as protected if it is to become available in the inheritance chain.
3. While constructing an object referred to by i firstly constructor of index class will be called followed by constructor of index1 class.
4. Constructor of index class does not get inherited in index1 class.
5. count should be declared as Friend if it is to become available in the inheritance chain.

namespace CompSciBitsConsoleApplication
{ 
    class index
    {
        protected int count;
        public index()
        {
            count = 0;
        }
    }
    class index1: index
    {
        public void increment()
        {
            count = count +1;
        }
    }
    class MyProgram
    {
        static void Main(string[] args)
        {
            index1 i = new index1(); 
            i.increment(); 
        }
    }
}
Discuss
Answer: (b).2, 3, 4
Q19.
What will be the size of the object created by the following C#.NET code snippet?

namespace CompSciBitsConsoleApplication
{ 
    class Baseclass
    {
        private int i; 
        protected int j; 
        public int k;
    }
    class Derived: Baseclass
    {
        private int x; 
        protected int y; 
        public int z;
    }
    class MyProgram
    { 
        static void Main (string[ ] args)
        { 
            Derived d = new Derived();
        } 
    } 
}
Discuss
Answer: (a).24 bytes
Q20.
Which statement will you add in the function fun() of class B, if it is to produce the output "Welcome to CompSciBits.com!"?

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

Suggested Topics

Are you eager to expand your knowledge beyond C# Programming? We've curated a selection of related categories that you might find intriguing.

Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!