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

                }
// end class Employee2
this.name = n;
} // end constructor
//***************************************
public void readName()
{
Scanner stdIn = new Scanner(System.in);
System.out.print("Name: ");
this.name = stdIn.nextLine();
} // end readName
Figure 7.16a Driven class for Employee2 program
7.8 Constructors 269
 import java.util.Scanner;
public class Employee
{
}
// end class Employee
private String name;
//*****************************************
public void readName()
{
Scanner stdIn = new Scanner(System.in);
System.out.print("Name: ");
this.name = stdIn.nextLine();
} // end readName
Figure 7.15b Driven class for Employee program
This works even though there is no explicitly defined constructor because the Java compiler supplies a matching default zero-parameter constructor.
          Apago PDF Enhancer
import java.util.Scanner;
public class Employee2
 {
private String name;
//***************************************
public Employee2(String n)
{































































   301   302   303   304   305