1
Answer

What does this code do?

Arkay Mann

Arkay Mann

14y
2.4k
1
I'm learning c#.  Most things I do understand but in this book I'm reading is this example.

abstract class GenericCustomer {
    private string name;
    public GenericCustomer() {
        name = "<no name>";
    }
    // lots of other methods
}

class Nevermore60Customer: GenericCustomer {
    private uint highCostMinutesUsed;
    // other methods etc.
}

The class is instantiated with
GenericCustomer customer = new Nevermore60Customer();


I would understand this instantiation
Nevermore60Customer  customer = new Nevermore60Customer();
but I don't understand the example.

If I read it correctly it is creating an object of type GenericCustomer which is an abstract class (I didn't think you could do that) or is it a cast that creates a Nevermore60Customer but casts it as GenericCustomer (again I didn't think you could do that).

BTW I tried the code and it works.  I also tried
Nevermore60Customer  customer = new Nevermore60Customer();
and it works to.



Answers (1)