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 237 views
237 views asked Apr 25, 2017 by avibootz
1 answer 189 views
1 answer 196 views
1 answer 124 views
124 views asked Oct 16, 2022 by avibootz
...