October 2008
Beginner to intermediate
680 pages
16h 48m
English
As we discussed earlier in this chapter, dot notation can potentially be used to access an object's field values, as in the following simple example:
Student x = new Student(); // Set the value of the name field of Student x. x.name = "Fred Schnurd"; // Retrieve the value of x's name so as to print it. Console.WriteLine(x.name);
There is an obvious danger with giving all the data stored by a class public access. For example, if a student's GPA field was publicly accessible, an enterprising student could change his GPA simply by typing the following:
bob.gpa = 4.0;
In reality, therefore, objects often restrict access to some of their members (fields in particular). Such restriction is known as information ...
Read now
Unlock full access