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
x is a symbolic name that represents an integer value.
The "thing" that we've named x understands how to respond to a number of different operations, such as addition (+), subtraction (–), multiplication (*), division (/), logical comparisons (>, <, =), and so on that have been defined for the int type.
Whenever we want to operate on this particular integer value in our program, we refer to it via its symbolic name x:
if (x > 17) x = x + 5;
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
y is a symbolic name that refers to a Student object (an instance of the Student class).
The "thing" that we have named y understands how to respond to a number of different service requests—how to register for a course, drop a course, and so on—that have been defined by the Student class.
Whenever we want to operate on this particular object, we refer to y:
// Pseudocode. if (y hasn't chosen an advisor yet) Console.WriteLine ("Uh oh ...");
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;