Class Dog Code: (Parent Class)
public class Dog
{
//attributes
private String breed;
private int age;
private String color;
//Constructor
public Dog(String breed, int age, String color)
{
this.breed = breed;
this.age = age;
this.color = color;
}
//accessor method
public String getBreed()
{
return breed;
}
//mutator method
public void setBreed(String breed)
{
this.breed = breed;
}
//methods
public void run()
{
System.out.println("Every dog can run.");
}
public void bark()
{
System.out.println("Every dog can bark.");
}
}
Class GermanShepard Code: (Child Class)
public class GermanShepard extends Dog
{
//attributes
private String petName;
private double price;
//Constructor
public GermanShepard(String breed, int age, String color, String
petName, double price)
{
super(breed, age, color);
this.petName = petName;
this.price = price;
}
//method override
@Override
public void run()
{
super.run();
System.out.println("German Shepard runs faster.");
System.out.println(getBreed());
}
@Override
public void bark()
{
super.bark();
System.out.println("German Shepard bark louder.");
}
}