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 is namespace in oops?

572


What is lazy in c#?

588


What is pure abstract class in c#?

553


How we can create an array with non-default values?

597


How do you sort an array in c#?

582






Compare and contrast between the System.Array.CopyTo() and Clone()?

629


What are cshtml files?

568


How many types of interface are there in c#?

582


How do I create a dbml file?

582


How do I create a .exe file?

575


What are the Types of compatabilities and explain them

597


Is php better than c#?

580


How does the lifecycle of Windows services differ from Standard EXE?

600


Is int a struct in c#?

584


What is the default value of decimal in c#?

586