Page 276 - Introduction to Programming with Java: A Problem Solving Approach
P. 276

                242
Chapter 6 Object-Oriented Programming
}
// end class StudentId
public void setId(int id)
{
}
{
}
}
}
this.id = id;
public int getId()
return this.id;
//*********************************************************
public String getEmailAccount()
{
// Include "" in concatenation to convert to strings.
return "" + this.name.charAt(0) + this.id +
"@pirate.park.edu";
//*********************************************************
public boolean isValid()
{
Apago PDF Enhancer
return this.id >= 100000 && this.id <= 999999;
13. [after §6.13] Construct a UML class diagram for the Growth class in Figure 6.17, with the getSizeIncrement2 method of Figure 6.20 included.
Review Question Solutions
1. False. An object is an instance of a class.
2. Any number, including zero.
3. A class’s instance variables must be declared outside of all methods, and all instance variable declarations
should be located at the top of the class definition.
4. Instance variables are usually private to further the goal of encapsulation. That means an object’s data
is harder to access, and, consequently, harder to mess up. The only way for the data to be accessed from
outside of the class is if the data’s associated public methods are called.
5. The main method goes in the driver class.
6. Most of a program’s code should be in driven classes.
7. To access a private instance variable from within a main method, you have to use an instantiated
object’s reference variable and then call an accessor method. In other words, use this syntax: ‹reference-variable›.‹accessor-method-call›
8. A reference variable holds the memory location of an object.
9. Go back to where the method was called, and look at the reference variable which precedes the method
  name at that point. That reference variable is the one that the method uses whenever this is used.


























































   274   275   276   277   278