Java Reference
In-Depth Information
Employee e = new Employee(“George W.”, “Houston, TX”, 43);
System.out.println(s.getName() + “'s pay is $”
+ s.computePay());
((Hourly) h).setHoursWorked(50);
System.out.println(h.getName() + “'s pay is $”
+ h.computePay());
}
}
Listing 8.14
(continued)
The only problem with the AbstractDemo program is the statement:
Employee e = new Employee(“George W.”, “Houston, TX”, 43);
This statement does not compile, and generates the following compiler error:
C:\wiley\Chapter8\abstract\AbstractDemo.java:7: Employee is abstract;
cannot be instantiated
Employee e = new Employee(“George W.”, “Houston, TX”, 43);
^
1 error
If this statement is commented out, the program will compile and execute
fine, and the output is shown in Figure 8.6.
Abstract Methods
The abstract Employee class still has one peculiarity that I want to fix, and that
is the computePay() method that does not do anything except return 0.0. Don't
get me wrong—I want the computePay() method in the Employee class. Hav-
ing it there allowed us to take advantage of virtual method invocation in the
SmartBoss class.
Figure 8.6
The output of the AbstractDemo program.
Search WWH ::




Custom Search