Java Reference
In-Depth Information
Person
Teacher
Student
Teaching Assistant
FIGURE 8.4:
Example of multiple inheritance.
...
}
class
Student
extends
Person
{
...
}
class
TeachingAssistant
extends
Teacher
{
Student studentSuperObject ;
}
Of course, this design is not perfect and will prevent us from using some Java features
related to inheritance, such as polymorphism. However, since Java does not support multiple
inheritance, we have no choice but to simulate it using class containment.
8.4 Constructors of Subclasses
Let us go back to our superhero and villain example. If we add an empty and non-empty
constructors to the
FictionalCharacter
class, then we get the following version of the
class.
public class
FictionalCharacter
{
private
String name;
public
FictionalCharacter ()
{
}
public
FictionalCharacter(String name)
{
this
.name = name;
}
public
String getName ()
{
return
name ;
}
public void
setName( String name)
{