Which is the Best Java Web Framework ?

Java - How to decide if a member should belong to instance or be made static ?


Static members belong to the class and hence common to all instances, whereas instance variables have values which is unique to an instance. 


We have used Flower class to make two objects, flower1 and flower2. Now as different flowers can have different colors, we should make the property "color" as instance variable only. 

But If we expect all flowers to have a common color, the color property should be made static so as to avoid extra memory overhead and unnecessary setting the same color for each instance. Moreover if we have the variable as instance in such case, it will allow setting some other color for instances which is not desired. 
Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
comments powered by Disqus




×

Try our new Java Interview Questions Search Tool.

There are more than 1000 questions with practice tests.

It's updated daily and It's Awesome.


×

Try our new Java Practice Test tool.

There are more than 200 questions and expanding quickly. It's updated daily and It's Awesome.