Jennifer's FotoPage

By: Jennifer Davis

[Recommend this Fotopage] | [Share this Fotopage]
View complete fotopage

Thursday, 9-May-2013 02:47 Email | Share | Bookmark
Can two copies of class variable exist

Semantically speaking, and if I infer the meaning for Car and cost correctly, you do not want to use a static UNLESS you want ALL your cars to cost the same. In the real world cost of a car is a highly variable attribute even between the same model of the same make of a car due to trim, options etc.

The only wrinkle here is if there are multiple ClassLoaders involved. In this case there can be an instance of the given class within the context of each ClassLoader which would then have a separate set of static fields associated with it. Most, if not all, chinese dirt bike parts , Servlet J2EE containers use multiple ClassLoaders, typically one per web-app.

The ClassLoaders are typically hierarchical, such that you can access classes loaded from a parent ClassLoader. In this way, if you really need a global singleton across multiple web-apps, you generally try to have your singleton loaded in a root ClassLoader so that it can be accessed everywhere.

View complete fotopage

© Pidgin Technologies Ltd. 2016