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

                Figure 7.17a Employee3 class uses an instance constant
Apago PDF Enhancer
7.8 Constructors 271
 /**********************************************************
*
Employee3.java
Dean & Dean
This gives an employee a permanent name.
**********************************************************/
*
*
*
import java.util.Scanner;
public class Employee3
{
Scanner stdIn = new Scanner(System.in)
;
    declaration of instance constant
 public final String NAME;
//*******************************************************
public Employee3(String name)
{
this.NAME = name;
} // end constructor
initializationofinstanceconstant
   }
// end class Employee3
 /************************************************************
*
Employee3Driver.java
Dean & Dean
This instantiates an object and prints permanent attribute.
************************************************************/
*
*
*
import java.util.Scanner;
public class Employee3Driver
{
}
public static void main(String[] args)
{
Employee3 waitress = new Employee3("Angie Klein");
System.out.println(waitress.NAME);
   } // end main
// end class Employee3Driver
Output:
Angie Klein
direct access to instance constant
 Figure 7.17b Driver for the Employee3 class in Figure 7.17a

















































   303   304   305   306   307