Object as an array
Posted
by owca
on Stack Overflow
See other posts from Stack Overflow
or by owca
Published on 2010-03-21T17:06:03Z
Indexed on
2010/03/21
17:11 UTC
Read the original article
Hit count: 490
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 ?
© Stack Overflow or respective owner