Results 1 to 10 of 10
- 12-21-2010, 11:27 AM #1
Member
- Join Date
- Dec 2010
- Posts
- 5
- Rep Power
- 0
Can i including methods into a class ?
Is there a way i can include methods into a class, i dont mean using the extends but just have all the methods from a file/class be put into a other classes as if i typed them in there my self
Reason - I have a class called tools, it has several functions which do nothing amazing, they just life easier such as
public void print(text){ System.out.println(text); }
It doesn't need any special formatting, just needs to be included in all of my classes.
Thankyou !
- 12-21-2010, 11:56 AM #2
Member
- Join Date
- Dec 2010
- Posts
- 27
- Rep Power
- 0
You can include the files you need in the classpath and write the correct import statement in the class where they are needed, I think that's what you want.
- 12-21-2010, 12:05 PM #3
Member
- Join Date
- Dec 2010
- Posts
- 5
- Rep Power
- 0
- 12-21-2010, 02:04 PM #4
Member
- Join Date
- Dec 2010
- Posts
- 27
- Rep Power
- 0
Go to File -> Project properties and find where you can import files, can't tell exactly now, after you import them they will be on the classpath.
- 12-21-2010, 02:36 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Is this Tools class part of your project?
If so then you should be able to just do an import in the class you want to use these methods, assuming Tools is in a different package.
Then you can call the methods like:
Java Code:Tools.someToolsMethod();
- 12-21-2010, 02:58 PM #6
Member
- Join Date
- Dec 2010
- Posts
- 5
- Rep Power
- 0
- 12-21-2010, 03:01 PM #7
Member
- Join Date
- Dec 2010
- Posts
- 5
- Rep Power
- 0
- 12-21-2010, 03:17 PM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
What do you mean by import?
"import" is a word with meaning in Java.
Is the class already in your project?
What IDE are you using?
- 12-21-2010, 03:24 PM #9
Member
- Join Date
- Dec 2010
- Posts
- 5
- Rep Power
- 0
Right i said important because tolls said it "If so then you should be able to just do an import in the class"
Im using eclipse and the class is in the same project as the other class.
All i want is that when im compile my project the methods in a file are put into every class
- 12-21-2010, 03:33 PM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Right, so import the Tools class into the class(es) that need it.
At the top of the class (after any package declaration):
If they are in the same package, however, you don't even need to do an import.Java Code:import <whatever package it's in>.Tools;
And then you can use the methods as I showed above.
Similar Threads
-
Methods in Object class
By Navatha in forum New To JavaReplies: 1Last Post: 09-28-2010, 11:17 PM -
How can I call abstract class methods from another class
By srinivas2828 in forum New To JavaReplies: 13Last Post: 03-12-2010, 02:33 PM -
Concept about methods of Class
By s021126 in forum New To JavaReplies: 9Last Post: 08-25-2009, 04:23 AM -
How to Cal methods within a method in the same class
By Manfizy in forum New To JavaReplies: 8Last Post: 03-03-2009, 08:28 AM -
Declare methods in a class
By Adiel224 in forum New To JavaReplies: 5Last Post: 09-19-2008, 10:38 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks