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

Give some examples for built in datatypes in c#?

552


What is session variable in c#?

561


What are the types of operator?

457


What is a variable in c#?

475


What is response redirect in c#?

483






Explain more on CLR

751


What is dto c#?

484


Are c# strings immutable?

489


Why do we need ienumerable in c#?

464


What is a cs file?

522


Can we inherit private class in c#?

492


what is the default access for a class

580


What framework is used for performance testing/load testing?

1482


Can extension methods access private members?

514


How do you define a predicate?

486