C# Interfaces, Inheritance & Polymorphism Mcqs

Our collections of Multiple choice questions and answers focuses on study of Interfaces, Inheritance & Polymorphism. These questions are chosen from a collection of most authoritative and best reference books on C# Interfaces,Inheritance & Polymorphism. Our aim is to prepare an individual for competitive exams like NTS, GAT, ECAT, University and College entrance exams and various Interfaces,Inheritance & Polymorphism comprehensively.

1.
Which of the following statements is correct about the C#.NET code snippet given below?
interface IMyInterface
{ 
    void fun1(); 
    int fun2();
}
class MyClass: IMyInterface
{ 
    void fun1()
    { } 
    int IMyInterface.fun2()
    { } 
}

A function cannot be declared inside an interface.

A subroutine cannot be declared inside an interface.

A Method Table will not be created for class MyClass.

The definition of fun1() in class MyClass should be void IMyInterface.fun1().

3.
A class implements two interfaces each containing three methods. The class contains no instance data. Which of the following correctly indicate the size of the object created from this class?

12 bytes

24 bytes

0 byte

8 bytes

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

One class can implement only one interface.

In a program if one class implements an interface then no other class in the same
program can implement this interface.

From two base interfaces a new interface cannot be inherited.

Properties can be declared inside an interface.

5.
Which of the following statements is correct about Interfaces used in C#.NET?

All interfaces are derived from an Object class.

Interfaces can be inherited.

All interfaces are derived from an Object interface.

Interfaces can contain only method declaration.

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

If a class implements an interface partially, then it should be an abstract class.

A class cannot implement an interface partially.

An interface can contain static methods.

An interface can contain static data.

7.
Which of the following statements is correct about an interface?

One interface can be implemented in another interface.

An interface can be implemented by multiple classes in the same program.

A class that implements an interface can explicitly implement members of that interface.

The functions declared in an interface have a body.

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

1. A class can implement multiple interfaces.
2. Structures cannot inherit a class but can implement an interface.
3. In C#.NET, : is used to signify that a class member implements a specific interface.
4. An interface can implement multiple classes.
5. The static attribute can be used with a method that implements an interface declaration.

1, 2, 3

2, 4

3, 5

None of the above.

9.
Which of the following is the correct implementation of the interface given below?
 interface IMyInterface
{ 
    double MyFun(Single i);
}

 class MyClass
{
    double MyFun(Single i) as IMyInterface.MyFun
    {
        // Some code
    }
}

class MyClass 
{
    MyFun (Single i) As Double
    {
        // Some code
    } 
} 

class MyClass: implements IMyInterface
{
    double fun(Single si) implements IMyInterface.MyFun()
    {
        //Some code
    } 
} 

class MyClass: IMyInterface
{
    double IMyInterface.MyFun(Single i)
    {
        // Some code
    } 
} 

10.
Which of the following statements is correct?

When a class inherits an interface it inherits member definitions as well as its implementations.

An interface cannot contain the signature of an indexer.

Interfaces members are automatically public.

To implement an interface member, the corresponding member in the class must be public as well as static.

11.
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.

1, 2

1, 4, 5

3, 4

3 only

13.
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
    } 
} 

Class MyClass is an abstract class.

Class MyClass cannot contain instance data.

Class MyClass fully implements the interface IMyInterface.

The compiler will report an error since the interface IMyInterface is only partially implemented.

14.
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(); 
}

Properties cannot be declared inside an interface.

This is a perfectly workable interface.

The properties in the interface must have a body.

Subroutine in the interface must have a body.

15.
Which of the following is the correct way to implement the interface given below?
interface IPerson
{ 
    String FirstName
    {
        get;
        set; 
    } 
} 

 class Employee : IPerson
{
    private String str; 
    public String FirstName
    {
        get
        { 
            return str;
        } 
        set
        { 
            str = value;
        } 
    } 
}

 class Employee
{
    private String str;
    public String IPerson.FirstName
    { 
        get
        { 
            return str;
        } 
        set
        { 
            str = value;
        } 
    } 
}

 class Employee : implements IPerson
{
    private String str; 
    public String FirstName
    { 
        get
        { 
            return str;
        } 
        set
        {
            str = value; 
        } 
    } 
}

None of the above

0Shares
0
Scroll to Top