• Post Reply Bookmark Topic Watch Topic
  • New Topic

array and objects  RSS feed

 
ekte spiriopoulos
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have super class abstract Animal
I have a class monkey that extends Animals.
I have a class extends cat extends Animals .I have and a class dog and extends Animal.
I could create an array and inside this array of 3 will get in possition 1 the whole class monkey ..The position 2 the cat and the position 3 the dog .So that the whole array will run and will execute the whole class .Can happen like this?
 
Fred Kleinschmidt
Bartender
Posts: 560
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ekte spiriopoulos wrote:So that the whole array will run and will execute the whole class .Can happen like this?

You will have to explain what you mean. You don't run arrays, and you don't "execute a whole class".
 
ekte spiriopoulos
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fred Kleinschmidt wrote:
ekte spiriopoulos wrote:So that the whole array will run and will execute the whole class .Can happen like this?

You will have to explain what you mean. You don't run arrays, and you don't "execute a whole class".
If not happen that.Could it be if on a class monkey I create an array and in this specific array to have the name (private String name; which I create up to my code) ,the age (private int age;) ,the food (private int food;) .To make and array with this fields?or I can't ?
 
Campbell Ritchie
Marshal
Posts: 55793
164
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried it? You can write a few lines of code and see what happens.
 
Knute Snortum
Sheriff
Posts: 4091
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An array can't have fields, but a class can. Maybe posting the code you are thinking of will help, or try it yourself.
 
ekte spiriopoulos
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Have you tried it? You can write a few lines of code and see what happens.
I haven't try it . I don't know how to do that to put inside in the same array string and int
 
Campbell Ritchie
Marshal
Posts: 55793
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute has already told you; those fields belong inside a class. Then you create an array to encapsulate instances of that class. You will probably need an Animal[] array.
 
ekte spiriopoulos
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Knute has already told you; those fields belong inside a class. Then you create an array to encapsulate instances of that class. You will probably need an Animal[] array.
thanks sorry I dint understand it before
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!