Is it compulsory to have atleast one abstract method in
abstract class?
Answer Posted / jatin
NO,It is not mandatory to write abstract members in Abstract
Class. I Repeat <IT IS NOT MANDATORY> ,If anyone have doubt
regarding this than simply make a program then everything
will be cleared, FOR YOUR CLARIFICATION I AM MAKING 1 SIMPLE
PROGRAMME FOR U GUYS
HOPE U WILL ENJOY AFTER READING THIS ..
program in console application:
namespace ConsoleApplication1
abstract class absClass
{
//A Non abstract method
protected virtual int AddTwoNumbers(int a, int b)
{
return a + b;
}
}
class absDerived : absClass
{
protected override int AddTwoNumbers(int Num1, int Num2)
{
int n = Num1 + Num2;
Console.WriteLine("sum of method is:" + n);
return n;
}
static void Main()
{
//You can create an
//instance of the derived class
absDerived calculate = new absDerived();
int sum = calculate.AddTwoNumbers(10, 20);
Console.WriteLine("{0}", sum);
Console.Read();
}
}
}
All the best ... :)
| Is This Answer Correct ? | 4 Yes | 2 No |
Post New Answer View All Answers
How will you initialize an Applet?
What do you mean by an interface in java?
Is main a function?
What is the purpose of declaring a variable as final?
What is a ternary operator in java?
What is role of void keyword in declaring functions?
What is a lightweight component?
What are the differences between include directive and include action?
How do you create a method in java?
What is the syntax and characteristics of a lambda expression? Explain
Why java is considered as platform independent?
When we serialize an object does the serialization mechanism saves its references too?
How do you check if a string contains only numeric digits?
Why do we use return statement?
Is .net better than java?