How to use override to modify the the implementation of an inherited method in C#

1 Answer

0 votes
using System;

abstract class Shape {
    public abstract int Area();
}

class Square : Shape {
    int a;

    public Square(int _a) => a = _a;

    public override int Area() => a * a;

    static void Main() {
        var sq = new Square(8);
        
        Console.WriteLine(sq.Area());
    }
}




/*
run

64

*/

 



answered Nov 27, 2020 by avibootz

Related questions

2 answers 217 views
217 views asked Apr 25, 2017 by avibootz
1 answer 184 views
1 answer 175 views
1 answer 113 views
113 views asked Oct 16, 2022 by avibootz
...