• Post Reply Bookmark Topic Watch Topic
  • New Topic

static question  RSS feed

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i cant figure out why did they put static
on oe variable
and not on the other

private int sp;
private Object[] data;
private static final int DEFAULT_SIZE = 5;
private static final int RESCALE = 5;
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess it depends on the *need*.

A similar question posted by you is answered here.

I believe that will help you get an answer
 
johny doe
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i noticed that the static ones dont change while the others
changes

is that what its all about??
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by johny doe:
i noticed that the static ones dont change while the others
changes

is that what its all about??


don't change means? in what context? Actually they are NOT bound to any specific instance of a class, rather to the whole class in common.

You can go for 'static' when you want to have some common data for all your instances of a class. Otherwise, each instance will have its own copy of the variables if declared non-static.
 
johny doe
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i make non static mathod
how do i call it from a static mathod??
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for quoting my post, Raghavan Muthu.

There is another similar thread, probably with better discussion on, here.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need to do anything to make a method "non-static" (it would be better to call it an "instance method"). All you have to do is not write "static."

You can't get access to an instance member of a class from a static method.
 
johny doe
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the difference between
when i define variable as
int

and

integer

what is the differnce between the two??
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Johny Doe,

Are you listening to the answers to your queries first? Pay attention to the answers firt.

Moreover, please do NOT post an irrelevant and a new question in an already running thread. Kindly use one thread per question.

Start a new thread for your int, integer difference question. Hope you will stick to the rules of the forum.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
muthu,

if you want to answer the quesions pls do the clarification here itself..dont link with other questions and all...

raja
SCJP 1.4
 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by thirumala raju:

if you want to answer the quesions pls do the clarification here itself..dont link with other questions and all...


Quoting the FAQ, as Muthu is doing, is absolutely the correct thing to do; please take the time to learn about our community's norms before going about telling folks how to behave. Thanks.
 
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by thirumala raju:
if you want to answer the quesions pls do ...

Please use real words when posting to the forums. Abbreviations such as "pls" in place of "please" only serve to make your posts more difficult to read and less likely to generate useful responses.

Please read this for more information.

thanks,
bear
JavaRanch sheriff
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!