can you overload a method of class A in Class B if it is
derived class of A?If it is yes tell me how is it possible?
Answers were Sorted based on User's Feedback
Answer / lalit pradhan
namespace Test
{
class Program
{
static void Main(string[] args)
{
A a = new A();
a.Method();
B b = new B();
b.Method("From B");
Console.ReadKey();
}
}
class A
{
public void Method()
{
Console.WriteLine("From A");
}
}
class B : A
{
public void Method(string s)
{
Console.WriteLine(s);
}
}
}
Is This Answer Correct ? | 15 Yes | 1 No |
Answer / dhanunjaya
yes,we can overload.Most of the times we can overload a
method within same class only but overloading is possible
between classes.So internally overloading is possible in
class B.
Is This Answer Correct ? | 9 Yes | 0 No |
Answer / bhagyashri
C# Support Inheritance & in C# multiple inheritance is
achieved by using interface.multiple interface means one
class can derived by two class..and class can be derived
only one class but more than one interface.so for multiple
inheritance we use interface
for eg:
interface i1
{
public void Method1();
}
interface i2
{
public void Method2();
}
class A:i1,i2
{
public void Method1()
{
Console.WriteLine("Hi");
}
public void Method2()
{
Console.WriteLine("Hello");
}
}
class main()
{
public static void Main()
{
A a=new A();
a.Method1();
a.Method2();
Console.ReadLine();
}
}
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / muralik.it
for the above answers, i have one doubt, c# doesnt support
inheritence instead of that we use interface..but the above
answers showing the inheritence can u plz clarifyit..thank you
Is This Answer Correct ? | 0 Yes | 3 No |
What is a decimal in c#?
Is static class thread safe in c#?
What is multithreading with .net?
What is session state in asp net c# with example?
if i used stored procedure for retrieving the data from sql server.in front end i had used data reader.when 100 records are there in table.when it has displayed ten records in frontend database has been collapsed.then where should our data available...
What is difference between value and reference types ?
Write a console application and implement the ternary operator to decide whether the age a user entered after being prompted is allowed to vote or not(given that only citizens between 18 and 120 years only inclusive can vote). Use exception handling for non-numerical input.
What is meant by unicode characters?
How does bubble sort work?
What is command object in c#?
What is main thread in c#?
What are predicates in c#?