Team LiB
Previous Section Next Section

User-Defined Types and Reference Variables

In a non-OO programming language such as C, the statement

  int x;

is a declaration that variable x is an int(eger), one of several simple, predefined types defined to be part of the C language.

What does this really mean? It means that

In an object-oriented language like C#, we can define a class such as Student, and then declare a variable as follows:

  Student y;

What does this mean? It means that

Note the parallels between y as a Student in the preceding example and x as an int earlier. Just as int is a predefined type (in both C and C#), the Student class is a user-defined type. And, because y in the preceding example is a variable that refers to an instance (object) of class Student, y is informally known as a reference variable.

Names for (nonattribute) reference variables follow the same convention as method and attribute names: i.e., they use Pascal casing. Some sample reference variable declarations are as follows:

  Student x;
  Student aStudent;
  Course prerequisiteOfThisCourse;
  Professor myAdvisor;

Team LiB
Previous Section Next Section