interface a
{
Method1()
Method2()
}
class b: a
{
override Method1()
override Method2()
}

what will happen & why?

Answer Posted / rajeev kumar

1.Method1() and Method2() are not having the ";" for termination .So it is a compile time error.

2.Method must have a return type.So it is a compile time error.

3.Method1() and Method2() must declare a body because it is not marked abstract, extern, or partial .
So it is a compile time error.
It should be like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
interface a
{
void Method1();
void Method2();
}

class b: a
{

public void Method1()
{
Console.WriteLine("From Method1()");
}
public void Method2()
{
Console.WriteLine("From Method2()");
}
}
class Program
{
static void Main(string[] args)
{
b obj=new b();
obj.Method1();
obj.Method2();

}
}
}

Output:
From Method1()
From Method2()

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What do you mean by expression tree?

445


Is vs as c#?

509


What is the default value of boolean variable?

454


What is array and its types in c#?

522


What's the difference between System.String and System..StringBuilder in C#?

501






Is array a collection c#?

526


Can I fly with a loop recorder?

477


Can we have multiple threads in one app domain?

519


What Is An Interface Class?

554


Enlist the different types of classes in c#?

522


What is difference between override and new in c#?

508


Can scriptable objects have methods?

491


What are virtual destructors?

505


How many types of methods are there in c#?

520


What is a thread c#?

491