I tried to implement abstract class and interface in a class and only interface members got called and abstract method didnt?

Zaheen Haris
public abstract class AbsClass
{
    public abstract int Add(int num1, int num2);
}
public interface Iinterface1
{
     void print1();
}
public interface Iinterface2
{
     void print2();
}
class Program : AbsClass,Iinterface1,Iinterface2
{
    public void print1()
    {
        Console.WriteLine("Print I1");
    }
    public void print2()
    {
        Console.WriteLine("Print I2");
    }

    public override int Add(int num1, int num2)
    {
        return num1 + num2;
    }
    public static void Main()
    {
        Program p = new Program();
        p.Add(20, 40);
        p.print1();
        p.print2();
        Console.ReadKey();
    }
}

}

I tried to implement both abstract and interface in a single class and only interface methods got called and abstract did not, I am a beginner in programming..

AGB

You just need to actually use the return value of p.Add(20, 40); try:

public static void Main()
{
    Program p = new Program();
    int sum = p.Add(20, 40);
    Console.WriteLine("The sum of 20 and 40 is " + sum);
    p.print1();
    p.print2();
    Console.ReadKey();
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Abstract Class with only abstract methods and Interface - Which should I use?

From Dev

Abstract class ,class, interface

From Dev

Abstract class implement a generic Interface Type

From Dev

How to implement Interface to an abstract class which is constraint?

From Dev

How to implement Interface to an abstract class which is constraint?

From Dev

Abstract class as functional interface

From Dev

Java - abstract class and interface

From Dev

Interface, abstract class, and the implementation

From Dev

Interface with abstract class

From Dev

Using Interface and Abstract class

From Dev

Interface vs Abstract Class with an empty method

From Dev

Java Overriding abstract class method with an interface as param

From Dev

Does abstract class hide or override the method of the interface?

From Dev

Interface, Abstract Class and Methods of Abstract Class

From Dev

Difference between abstract class with all method abstract and interface?

From Dev

The class design - interface or abstract class?

From Dev

Should I use an interface or abstract class in this scenario?

From Dev

Cannot create an instance of the abstract class or interface, but it is not an abstract class and it's not an interface?

From Dev

Class must be declared as abstract or implement abstract method

From Dev

AutoConfiguredMoqCustomization with abstract class implementing interface

From Dev

operator overloading in abstract class(interface)

From Dev

Choose between abstract class and interface

From Dev

Use @NodeEntity on interface/abstract class

From Dev

Gson serialize interface / abstract class

From Dev

Implementing an Interface Parameter in Abstract Class

From Dev

Why Abstract Class Implementing Interface?

From Dev

Declare abstract signal in interface class

From Dev

PHP use abstract class or interface?

From Dev

Extending a non abstract class and implementing an interface with same method signatures in a class

Related Related

  1. 1

    Abstract Class with only abstract methods and Interface - Which should I use?

  2. 2

    Abstract class ,class, interface

  3. 3

    Abstract class implement a generic Interface Type

  4. 4

    How to implement Interface to an abstract class which is constraint?

  5. 5

    How to implement Interface to an abstract class which is constraint?

  6. 6

    Abstract class as functional interface

  7. 7

    Java - abstract class and interface

  8. 8

    Interface, abstract class, and the implementation

  9. 9

    Interface with abstract class

  10. 10

    Using Interface and Abstract class

  11. 11

    Interface vs Abstract Class with an empty method

  12. 12

    Java Overriding abstract class method with an interface as param

  13. 13

    Does abstract class hide or override the method of the interface?

  14. 14

    Interface, Abstract Class and Methods of Abstract Class

  15. 15

    Difference between abstract class with all method abstract and interface?

  16. 16

    The class design - interface or abstract class?

  17. 17

    Should I use an interface or abstract class in this scenario?

  18. 18

    Cannot create an instance of the abstract class or interface, but it is not an abstract class and it's not an interface?

  19. 19

    Class must be declared as abstract or implement abstract method

  20. 20

    AutoConfiguredMoqCustomization with abstract class implementing interface

  21. 21

    operator overloading in abstract class(interface)

  22. 22

    Choose between abstract class and interface

  23. 23

    Use @NodeEntity on interface/abstract class

  24. 24

    Gson serialize interface / abstract class

  25. 25

    Implementing an Interface Parameter in Abstract Class

  26. 26

    Why Abstract Class Implementing Interface?

  27. 27

    Declare abstract signal in interface class

  28. 28

    PHP use abstract class or interface?

  29. 29

    Extending a non abstract class and implementing an interface with same method signatures in a class

HotTag

Archive