overriding abstract methods in an inherited abstract class

前端 未结 2 1111
天命终不由人
天命终不由人 2021-02-08 21:04

Okay so basically I have the following problem: I\'m trying to have an abstract class inherit another abstract class that has an abstract method, but I don\'t want to implement

2条回答
  •  别那么骄傲
    2021-02-08 21:22

    You don't need to declare execute() in the Binary class since it's already inherited from Command. Abstract methods don't need to be implemented by other abstract classes - the requirement is passed on to the eventual concrete classes.

    public abstract class Command
    {
        public abstract object execute();
    }
    
    public abstract class Binary : Command
    {
        //the execute object is inherited from the command class.
    }
    
    public class Multiply : Binary
    {
        public override object execute()
        {
            //do stuff
        }
    }
    

提交回复
热议问题