Inheritance
Shape is a base class: it holds what every shape shares. Name stores a name, and Info() describes the shape. Because Shape is abstract, you cannot write new Shape(...); it exists only to be inherited from.
The colon in class Square(...) : Shape("Square") means Square inherits from Shape: a Square is a Shape. It gets Name and Info() for free and adds its own data, side. Rect does the same with w and h.
new Square(3) makes one object on the heap. It holds the Shape part, Name = "Square", and the Square part, side = 3. new Rect(2, 5) does the same: Name = "Rect", w = 2, h = 5.
Override and polymorphism
Shape declares Area() as abstract: a method with no body that every derived class must write. Square and Rect each override it with their own formula: side * side, and w * h.
shapes is an array of Shape. A Square or a Rect converts to Shape automatically, because each one is a Shape. The array holds references to the two objects, not copies, and each object stays what it is.
In the loop, s.Info() runs Shape's Info(), which calls Area(). Area is virtual, so at run time .NET looks at the object's real type, Square, and runs Square's override: 3 * 3 = 9. The console shows Square: 9.
Next time round the loop, s refers to the Rect. The very same line now runs Rect's override: 2 * 5 = 10, so the console shows Rect: 10. One line, different behaviour for each object: that is polymorphism.
Interfaces
interface IShape lists what a type promises to have, here double Area(), with no data of its own. Shape : IShape signs that contract, so Shape, and every class derived from it, must have a public Area().
IShape x = re; makes a reference that knows only the contract. x.Area() still reaches the Rect object and runs Rect's override, so the console shows 10. Code written for IShape works with any class that implements it.
A C# class has exactly one base class (Shape's is object), but it can implement many interfaces, listed after the base. Inherit to share code and data; implement an interface to promise behaviour that unrelated classes can share too.
What happens
// step 1/10 · base-class
1 abstract class Shape(string name) : IShape
2 public string Name { get; } = name;
3 public abstract double Area();
4 public string Info() => $"{Name}: {Area()}";
abstract no objects of this exact type: new Shape("x") is error CS0144
shared Name and Info() are written once, here
The code cards leave out each type's braces { } and the indentation. The full Program.cs is shown on this page; it builds with no warnings on .NET 8 (C# 12), which added primary constructors and collection expressions. Square(double side) is a primary constructor. Because Area() uses side, the compiler stores it in a hidden private field of the object; the figure simply calls that field side. Name is a property with its own hidden backing field.