Animais Pacote Animals: Classe Animals
package br.com.diego.Animals;
public class Animals {
public String getEmitSound() {
return emitSound;
}
public void setEmitSound(String emitSound) {
this.emitSound = emitSound;
}
String emitSound;
public String getFunction() {
return function;
}
public void setFunction(String function) {
this.function = function;
}
String function;
public void TestAnimals() {
System.out.println("Sound: " + emitSound);
System.out.println("Function: " + function);
}}
Classe Cat
package br.com.diego.Animals;
public class Cat extends Animals {
// Cat cat = new Cat();
String emitSound = "Meow";
String function = "Scratch the furniture";
@Override
public void setEmitSound(String Meow) {
super.setEmitSound(emitSound);
}
@Override
public String getEmitSound() {
return super.getEmitSound();
}
}
Classe Dog
package br.com.diego.Animals;
public class Dog extends Animals {
// Dog dog = new Dog();
String emitSound = "Woof";
String function = "Move tail";
@Override
public void setEmitSound(String Woof) {
super.setEmitSound(emitSound);
}
@Override
public String getEmitSound() {
return super.getEmitSound();
}
}
Classe Test Animals
package br.com.diego.Animals;
import org.w3c.dom.ls.LSOutput;
public class TestAnimals extends Animals {
public static void main(String[] args) {
Dog dog = new Dog();
dog.setEmitSound("Woof");
System.out.println("Dog's noise is: " + dog.emitSound);
System.out.println("Dog's function is: " + dog.function);
Cat cat = new Cat();
cat.setEmitSound("Meow");
System.out.println("Cat's noise is: " + cat.emitSound);
System.out.println("Cat's function is: " + cat.function);
}
}