Home arrow static arrow Java Programming [Archive] - calling methods from other classes
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - calling methods from other classes
This topic has 3 replies on 1 page.

Posts:67
Registered: 2/8/04
calling methods from other classes  
Aug 6, 2004 1:10 PM



 
I have a bunch of little java files in a folder, do I need to make a package in order to access all the methods in all the classes, or can I just make an instance of any of the methods because all the classes are in the same folder?
 

Posts:14,142
Registered: 99-04-02
Re: calling methods from other classes  
Aug 6, 2004 1:15 PM (reply 1 of 3)



 
It is generally considered proper to put all classes into some package.... I assume you mean package like Java class packages, and not package like packaging them into a Jar file. If it's the Jar file thing, that is not needed, as long as the directory the classes are in are in the classpath.
 

Posts:104
Registered: 04-07-20
Re: calling methods from other classes  
Aug 6, 2004 1:16 PM (reply 2 of 3)



 
packages arent necessary but are recommended as a best practice. you may access other classes' methods as long as they are declared public (or protected if youre using inheritance).
 

Posts:826
Registered: 7/1/03
Re: calling methods from other classes  
Aug 6, 2004 1:22 PM (reply 3 of 3)



 
HI,

If your methods have a "public" modifier (and the class does too) then you can instantiate your classes as objects from that (so-called) "default" package in any other class or object in any other package and then call the methods on those instantiated objects as you please.

If that sounds confusing... I'd seriously try the excellent tutorials at this site, especially "the java tutorial".

/k1
 
This topic has 3 replies on 1 page.