I have abstract class Animal and inheritance classes Fish and Dog. I need to create various objects of fish and dogs and give them names and breeds and also make methods of the way they move. Finally i need to create an array of them and do 4 random prints that will show their name and breed.
Main Class:
public class JavaApplication38 {
public static void main(String[] args) {
Animal[] arr = new Animal[20];
arr[0] = new Fish("Riby", "Sea Fish");
arr[1] = new Dog("Any", "Great Dane");
arr[2] = new Fish("Ribytsa", "River fish");
arr[3] = new Dog("Jackie", "Pug");
arr[4] = new Fish("Bobi", "Mix");
arr[5] = new Dog("Ruby", "Labrador");
}
}
Animal class
public abstract class Animal {
public Animal(String name, String breed){
}
public Animal(){
}
public abstract void moving();
}
Dog class
Public class Dog extends Animal{
private String breed;
private String name;
public Dog(){
}
public Pas(String name, String breed){
this.name = name;
this.breed =breed;
}
@Override
public void moving() {
System.out.print("Walk\n");
}
}
Fish class
public class Fish extends Animal {
private String breed;
private String name;
public Fish(){
}
public Fish(String name, String breed){
this.name = name;
this.breed= breed;
}
@Override
public void moving(){
System.out.print("Swims\n");
}
}
The question is, what do i have to write in a loop to print names and breeds via array?
breedandnameinto the abstractAnimalclass?