abstract class GenericCustomer {
private string name;
public GenericCustomer() {
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.
Jaish MathewsPosted Apr 15, 2010, 2:32 AM
Nevermore60Customer customer = new Nevermore60Customer();
and on executing "customer.GetType()" you can see it's "Nevermore60Customer" type. To avoid confusion remember like whish type has "new" key word that type object will be created. We have "new Nevermore60Customer(); " and thay type will be created. Below another class created like
class Nevermore60Customer1 : GenericCustomer
{
private uint highCostMinutesUsed;
// other methods etc.
}
and object created by
GenericCustomer customer1 = new Nevermore60Customer1();
Here new Nevermore60Customer1(); used. So object type is Nevermore60Customer1
You want to undeerstand that this is the purpose of abstract calss and interfaces. A common abstract type can be instantiated with different other types.