Java Reference
In-Depth Information
public Pet(String name, int location, double price)
{
this.petName = name;
this.petLocation = location;
this.petPrice = price;
}
// Concrete methods in the base class
public void getName()
{
System.out.println ("Pet name: " + this.petName);
return;
}
public void getLocation()
{
System.out.println("Pet location: " + this.petLocation);
return;
}
public void getPrice()
{
System.out.println("Pet price: " + this.petPrice);
return;
}
// Abstract method
public abstract void getSpecData();
j}
//************************************
// concrete classes
//************************************
class Dog extends Pet
{
// Data specific for the Dog class
String dogBreed;
int dogAge;
// Constructor for the Dog class uses the constructor
// if the superclass
public Dog(String name, int loc, double price, String race)
{
// Call the constructor in Pet
super(name, loc, price);
// Fill-in the dog-specific data
this.dogBreed = race;
}
// Concrete methods in subclass
public void getSpecData()
{
System.out.println("Dog race :" + this.dogBreed);
return;
}
}
Search WWH ::




Custom Search