Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static

 
Prasad Chelur
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sir please give me some real time example where we can use static method(we have to use only static method)
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prasad,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean an example of the use of static methods in solving a real-time programming problem?
You would not normally choose Java to implement a real-time (even soft real-time) process because of the possible impact of garbage collection (even if it runs as a low-priority thread).
Do you have an example of an example in mind?
Maybe you mean a program using just primitive data types and static methods, or possibly objects that once referenced are never released by setting the reference to null.
Could you mean something like LeJos a JVM (which has no garbage collection) developed for Lego (TM) Mindstorms RCX bricks?
-Barry
[ January 04, 2003: Message edited by: Barry Gaunt ]
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or do you just want an example of a static method?
 
k Oyedeji
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think he's asking for an example of when it would be appropriate to use a static method.
Kola
 
Robbie shi
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
specify that a member variable is a class variable, use the static keyword. For example, let's change the AnIntegerNamedX class such that its x variable is now a class variable:

-----
Robbies
-----------------------------
1.java IDE tool : JawaBeginer
2.Java Jar tool : JavaJar
web page
-----------------------------
 
kishor rao
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
say u want to keep count of how many objects of a class u have. then have a static counter and a static method to increment the static counter(cos only static methods can change static variables). have the constructor call the static method, so the static variable is changed everytime the class is instantiated.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic