2 Polymorphism Questions (I'm beginner : c )

Hi, thank you for your time!!

CONTEXT:

public abstract class Vehicle
{}

class Truck : Vehicle
{
    public int TowingCapacity;
}

Q1:

I tried to do this:

Vehicle myTruck = new Truck();
myTruck.TowingCapacity = 1200;

I got an Error: Vehicle does not contain a definition for TowingCapacity.

Why can’t I access TowingCapacity?

Q2:

I tried to do this:

 Truck myTruck = new Vehicle();

An error tells me: Cannot create an instance of the abstract class “Vehicle”.

Why is it that I can do
Vehicle myTruck = new Truck ();

but not
Truck myTruck = new Vehicle();?

Much Appreciated!!!

All of this (inheritance, virtual keywords, exact error messages… ) is standard C#, and there are many non-Unity sites with examples, explanations, places to ask… . They tend to be much more thorough and extensive than anything you’ll find on UA.

C# in Unity really does work 99.99% the same as every other use of C#. Even for things like a list of gameObjects. GameObjects are Unity only, but keeping a list of [whatever] is a standard C# topic, which many well-explained non-Unity examples which work the same way in Unity.

Hello,
Q1 : The Vehicle class is a parent class. It can’t access to thier child’s method and attribute. You can do a simple cast

Vehicle myTruck = new Truck();
 ((Truck)myTruck).TowingCapacity = 1200;

Q2 : In Object-oriented programming (OOP) you can’t instantiate abstract class, because it can have none implemented method.