Link to home
Start Free TrialLog in
Avatar of ram_os
ram_os

asked on

static method


Hi,

I have a method which I am calling from another class. Eclipse is forcing me to change the method to static and I dont know why.

Any ideas?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perhaps because you are calling it with the class-name? Can we look at the class that you're trying to call (I'm assuming you are calling it from another class). Also - is it an inner class by any chance? For the basics - a static method can be called by directly using the class-name and you don't need to create objects to call them.
Avatar of ram_os
ram_os

ASKER


no I havent created an instance, so whenever I call a method on another class that I havent created an instance of, the method has to be static?
>> so whenever I call a method on another class that I havent created an instance of, the method has to be static?
Yes.
>> so whenever I call a method on another class that I havent created an instance of, the method has to be static?

Yes.
A class basically defines a template for an entity. You define data-members inside it which are like its attributes and then you define methods that perform operations on those attributes. So if you want to do it for a specific instance of a class, the methods will be instance-methods. If the class, on the other hand, defines something like a utility and need not necessarily have instances as there will no difference between them, then you can make its methods static.
Avatar of ram_os

ASKER



ok, could that affect existing calls on the method that werent static but now are?
But I wouldn't tend to make every method you want to use outside your class static.
What's the problem in creating an instance and call it on that?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm leaving for the day now.
Avatar of ram_os

ASKER


ok, thanks for that
:-)
So, my comment - posted at the same time as CEHJ's - is useless?
Avatar of ram_os

ASKER


Sorry zzynx, cehz was there first, i suppose i should have split the points further, i didnt take notice of the posted times.
>> i suppose i should have split the points further
It's never too late. ;°)
Would you like me to ask a reopen of this Q so you can reclose applying another split?
Avatar of ram_os

ASKER


its up to yourself, would be only worth 50 points for you
>> its up to yourself
No, I ask it to you. Do you agree with a reopen?
>> would be only worth 50 points for you
Doesn't matter. For me, it's the principal that counts: a good comment that helped you deserves (some) points.
Avatar of ram_os

ASKER


Yep I agree