Java Reference
In-Depth Information
Solution
Extend the functionality of the base class by using the
extends
keyword followed by
the name of the class that you would like to extend. The following example shows two
classes. The first class, named
HockeyStick
, represents a hockey stick object. It will
be extended by the second class named
WoodenStick
. By doing so, the
WoodenStick
class will inherit all the properties and functionality contained within
HockeyStick
, with the exception of
private
variables and those that have the de-
fault access level. The
WoodenStick
class becomes a subclass of
HockeyStick
.
First, let's take a look at the
HockeyStick
class , which contains the basic properties
of a standard hockey stick:
public class HockeyStick {
public int length;
public boolean isCurved;
public String material;
public HockeyStick(int length, boolean isCurved,
String material){
this.length = length;
this.isCurved = isCurved;
this.material = material;
}
public int getlength() {
return length;
}
public void setlength(int length) {
this.length = length;
}
public boolean isIsCurved() {
return isCurved;
}
public void setIsCurved(boolean isCurved) {