Last post Jul 22, 2015 02:09 AM by Mikesdotnetting
Jul 21, 2015 04:57 AM|demoninside9|LINK
Below I tried to implement an abstract class. But when I run this it gives very strange result.
abstract class AbsClass
public abstract int MultiplyTwoNumbers(int x, int y);
public int AddThreeNumbers(int a, int b, int c)
return a + b + c;
class DerivedClass : AbsClass
public override int MultiplyTwoNumbers(int x, int y)
return x * y;
static void Main(string args)
DerivedClass obj = new DerivedClass();
int Addition = obj.AddThreeNumbers(10, 20, 30);
int Multipication = obj.MultiplyTwoNumbers(5, 20);
Console.WriteLine("Addition of 10, 20 and 30 = " + Addition.ToString() + "\n" + "Mutiplication of 5 and 20 = " + Multipication.ToString());
Addition is coming correct but multiplication is not coming, it shows addition instead of multiplication.
Jul 21, 2015 08:46 AM|Mikesdotnetting|LINK
The code is fine and outputs
Addition of 10, 20 and 30 = 60 Mutiplication of 5 and 20 = 100
The screen shot doesn't match up with the code, and I suspect you had code to add instead of multiply when you ran it previously.
Jul 21, 2015 11:34 PM|demoninside9|LINK
I suspect you had code to add instead of multiply when you ran it previously.
Yes Sir, I added this before but now I have changed the code and restarted the machine. But still the same result.
Jul 22, 2015 02:09 AM|Mikesdotnetting|LINK
Double check what you are doing. The code you posted will always give the result I posted. If you get a different result, you can't possibly be executing the same code.