interface a
{
Method1()
Method2()
}
class b: a
{
override Method1()
override Method2()
}
what will happen & why?
Answers were Sorted based on User's Feedback
Answer / vijayakumar
It will throw an error bcz
1.override Key word not use with interface
correct ans :
class b : a
{
public void Method1()
{
}
public void Method2()
{
}
}
| Is This Answer Correct ? | 2 Yes | 1 No |
Answer / arun
A compile time error will be thrown as there exist no
methods to override. The methods in the interface are just a
contract.
To override any method, it should be defined as virtual.
| Is This Answer Correct ? | 2 Yes | 1 No |
Answer / 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 |
Answer / nithya
It will through the error because
in interface,the methods should have return type for them.
And we can create only implementation for the methods
available in interface. We cannt override it.
And Virtual/Abstarct or not a valid items in interface.
We must implement the methods available in interface.
interface a
{
void Method1();
void Method2();
}
class b: a
{
public void Method1();
public void Method2();
}
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / sandeep joshi
without virtual keyword
cant override method
its error at compile time .....
| Is This Answer Correct ? | 0 Yes | 1 No |
How jit (just in time) works?
how can your software identify which version of dot net framework install in client pc and install framework accordingly
What are some of the commonly used commands in sqlcommand?
Can u create multiple threads of execution ?
1 Answers IBM, ITC Infotech, UHU,
What is uint64_t?
What is garbage collector and where should you use in .NET?
What is marshalling in c#?
If a method's return type is void, can you use a return keyword in the method?
what is inheritance and an example in vb.net and c# of when you might use it?
What is marshalling and what are different kinds of marshalling?
Why is it not a good idea to use empty destructors?
What is returned if you pass the value 12.34 to the parsefloat () function?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)