oop - How to affect all objects of a class? (Java) -


i bit unsure how formulate question. object oriented thinking, in case in java, it's more general concepts.

to practice arrays , inheritance , such want create little system there car objects can owned people objects, store cars in arrays. cars have value, , people objects can buy , sell cars each other money.

my question:

i want there there subroutine can call let year pass, increase year counter, , decrease price of cars existing in program, increase "age" 1. things that.

i realize have no idea how this; how perform such action, targets not specific object, every object of specific class? imagine type of operation common in big programs, how go it?

you cannot, really. @ least not cleanly.

first off, need hold reference car objects, or garbage collected (deleted memory).

since you're keeping reference them (probably under people objects), either go through people , cars, or keep separate container (say, arraylist) keeps cars. that'd mean cars available either through people, or separate container. itereate through container , wish on cars.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -