I need to create class Dog and PurebredDog extending Dog. Problem is that Dog can be at once single object and array of objects (Dogs and PurebreedDogs :
Dog pack[]={new Dog(76589,"As","black",18,
"Ann","Kowalsky"),
new PurebreedDog(45321,"Labrador","Elf","black",25,
"Angus","Mati","Barbara","Smith"),
new Dog(102467,"Gamma","brown",89,
"Josh","Coke"),
new PurebreedDog(9678,"York","Theta","brown",8,
"Emka","Figaro","Alice","Cat")};
for(int i=0; i < pack.length; i++)
System.out.println(pack[i]+"\n\n");
How to write proper constructor for Dog
?
You could do :
public Dog(String name, etc){
}
but how to write constructor for array of dogs ?
public Dog(Dog[]tab) ?
And then how to recall it's elements ? Is pack[]
a 2d array ?