Like Java, both C#'s variables and objects are typed. [7] Assuming that there are two classes Vehicle and Car , and Vehicle is the superclass of Car , you can have an object of class Car being referred to by a variable of type Vehicle . And, like Java, you cannot have a Vehicle object (object of a super type) referenced by a variable of type Car (variable of subtype). Similarly, you can explicitly cast an object to a superclass type.
|