Re: Help -- New to Java



Bjorn Abelli wrote:
The main difference from C in this aspect is that you need to use the keyword "static". Otherwise it becomes an "instance member" instead of a "class member".
No, you don't. This could just as well be an instance method.

Yes, he does, as his assignment explicitly says so... ;-)

You are correct. I was speaking outside the context of the OP's homework, wasn't I?

Actually, for methods the question of static vs. instance interests me. Is there a best practice (when a manager hasn't forced the choice for non-technical reasons)?

I lean towards making methods instance-level most of the time. For non-instantiable utility classes I use only static methods and no instance anythings.

Most of my instance methods are final (as their parameters usually are).

I figure this will give me the most power when I need to expand, secure or make thread-safe my classes, and doesn't carry a discernible penalty.

Some methods are inherently static, typically the sort that initialize an environment. If the design calls for it, that justifies it.

--
Lew
.



Relevant Pages

  • Re: Help -- New to Java
    ... Bjorn Abelli wrote: ... The main difference from C in this aspect is that you need to use the keyword "static". ... Otherwise it becomes an "instance member" instead of a "class member". ...
    (comp.lang.java.help)
  • Re: Non static method error explanation?
    ... programmer use...use/add the keyword "static" in the calledRoutine line ... then it must be an instance member. ... If the method accesses state that might be used by more than one ...
    (comp.lang.java.help)