Java Reference
In-Depth Information
class Cat extends Pet
{
// Data specific for the Cat class
String catBreed;
public Cat(String name, int loc, double price, String race)
{
// Call the constructor in Pet
super(name, loc, price);
// Fill-in the cat-specific data
this.catBreed = race;
}
// Concrete methods in subclass
public void getSpecData()
{
System.out.println("Cat race: " + this.catBreed);
return;
}
}
class Bird extends Pet
{
// Data specific for the Cat class
String birdColor;
public Bird(String name, int loc, double price, String color)
{
// Call the constructor in Pet
super(name, loc, price);
// Fill-in the cat-specific data
this.birdColor = color;
}
// Concrete methods in subclass
public void getSpecData()
{
System.out.println("Bird color: " + this.birdColor);
return;
}
}
//******************************************
//******************************************
// Driving class
//******************************************
//******************************************
public class PetStore
{
//*****************************
// methods
//*****************************
Search WWH ::




Custom Search