Java Reference
In-Depth Information
parent class ,or superclass ;andeachof Car and Truck isknownasthe derived class ,
child class , or subclass .
Caution Youcannotextenda final class.Forexample,ifyoudeclared Vehicle
as final class Vehicle ,thecompilerwouldreportanerroruponencountering
class Car extends Vehicle or class Truck extends Vehicle .
Developersdeclaretheirclasses final whentheydonotwanttheseclassestobeex-
tended (for security or other reasons).
Aswellasbeingcapableofprovidingitsownmemberdeclarations,eachof Car and
Truck iscapableofinheritingmemberdeclarationsfromits Vehicle superclass.As
Listing 2-22 shows, non- private inherited members become accessible to members
of the Car and Truck classes.
Listing 2-22. Inheriting members
class Vehicle
private String make;
private String model;
private int year;
Vehicle(String make, String model, int year)
this.make = make;
this.model = model;
this.year = year;
String getMake()
return make;
String getModel()
return model;
int getYear()
return year;
Search WWH ::

Custom Search