OOPS Interview Questions and Answers (133) - Page 7

What are the rules about Function Overriding?

NOTE: This is objective type question, Please click question title for correct answer.
Which statement is correct about Operator Overloading?

NOTE: This is objective type question, Please click question title for correct answer.
An interface has got four Interface methods (m1,m2,m3,m4) and implement these interface methods as follows. Implement m1() & m2() in base class Implement m3() & m4() in derived class

Declare an interface class
 interface myInterface

{
void m1();
void m2();
void m3();
void m4();
}

Declare Base class which inherits an Interface Class

public class mybaseClass:myInterface
{
public void m1()
{
Console.WriteLine("m1");
}
public void m2()
{
Console.WriteLine("m2");
}
public virtual void m3()
{ }

public virtual void m4()
{ }
}

Declare a Derived class which Inherits Base class & Interface Class

public class derivedClass : mybaseClass, myInterface
{

public override void m3()
{
Console.WriteLine("m3");
}
public override void m4()
{
Console.WriteLine("m4");
}
}


class Program

{
static void Main(string[] args)
{
derivedClass dc = new derivedClass();
dc.m1();
dc.m2();
dc.m3();
dc.m4();
Console.ReadKey();
}
}

An two interface has got same method names, how can you access differently.

Declare two interfaces with same method names
interface myInterface1

{
void m1();
}
interface myInterface2
{
void m1();
}

Implement the Interface method in Base Class

public class myClass : myInterface1, myInterface2
{
public void m1()
{
Console.WriteLine("m1 accessed");
}
}

Create an instance of base class & references of interface classes

class Program
{
static void Main(string[] args)
{
myClass mc = new myClass();
myInterface1 mi1 = (myInterface1)mc;
myInterface2 mi2 = (myInterface2)mc;
mc.m1();
mi1.m1();
mi2.m1();
Console.ReadKey();
}
}

Which statements are correct about Abstract classes in Dot Net?

NOTE: This is objective type question, Please click question title for correct answer.
What are the different ways a method can be Overloaded in C#?

NOTE: This is objective type question, Please click question title for correct answer.
Which class we can use when its member or method is directly called using class name?

NOTE: This is objective type question, Please click question title for correct answer.
Which class we can use when we do not have to create a constructor?

NOTE: This is objective type question, Please click question title for correct answer.
Which class we can make an object but can not inherit?

NOTE: This is objective type question, Please click question title for correct answer.
Which class is called to be inherit?

NOTE: This is objective type question, Please click question title for correct answer.
What is Static Constructor?

When constructors are used to set the value of a type's data at the time of construction, if we want the value of such static data is to be preserved regardless of how many objects of the type are created, we have to define the constructor with static keyword.

Example:
Class SimplestaticConstr

{
Static SimplestaticConstr()
{
//code inside this constructor
}
}

What are the different categories of Inheritance?

Inheritance in OOP is of four types :

Single inheritance : Contains one base class and one derived class.
Example :
public class Base

{
}
public class Derived: Base
{
}
Hierarchical inheritance : Contains one base class and multiple derived classes of the same base class.
Example:

public class Base

{
}
public class Derived1: Base
{
}

public class Derived2: Base
{
}


Multilevel inheritance : Contains a class derived from a derived class.
Example:

public class Base

{
}
public class Derived1: Base
{
}

public class Derived2: Derived1
{
}


Multiple inheritance : Contains several base classes and a derived class.

Example:

public class Base1

{
}
public class Base2
{
}

public class Derived1: Base1,Base2
{
}

What is sealed class?

Sealed classes are those classes which can not be inherited and thus any sealed class member can not be derived in any other class. A sealed class cannot also be an abstract class.

Simple Sealed Class.
sealed class SealedClass 

{

}


Simple Example Programming:

using System;

class ClassSeal

{

static void Main(string[] args)
{
SealedClass sealedCls = new SealedClass(); //Sealed class declaration
int total = sealedCls.Multiple(14, 53);
Console.WriteLine("Total = " + total.ToString());
}

}

// Sealed class Definition

sealed class SealedClass

{
public int Multiple(int x, int y)
{
return x * y;
}
}


Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories