Java Reference
In-Depth Information
public void setData( double u)
{
bX = u;
}
public void setData( char ch, double u)
{
bCh = ch;
bX = u;
}
public String toString()
{
return ("Superclass: bCh = " + bCh + ", bX = "
+ bX + '\n');
}
}
The definition of the class BClass contains the protected instance variable bCh of
type char , and the private instance variable bX of type double . It also contains an
overloaded method setData ; one version of setData is used to set both the instance
variables, and the other version is used to set only the private instance variable. The
class BClass also has a constructor with default parameters.
Next, we derive a class DClass from the class BClass . The class DClass contains
a private instance variable dA of type int . It also contains a method setData , with
three parameters, and the method toString .
public class DClass extends BClass
{
private int dA;
public DClass()
{
//The definition is as shown later in this section
}
public DClass( char ch, double v, int a)
{
//The definition is as shown later in this section
}
public void setData( char ch, double v, int a)
{
//The definition is as shown later in this section
}
public String toString()
{
//The definition is as shown later in this section
}
}
Search WWH ::




Custom Search