954,536 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Noob Question (using multiple files)

I'm trying to learn Java, pretty easy so far as my previous experiance is with C/C++. I was just curious how to call java classes from different files. That way I don't have to have main as well as all of my classes crammed into one file. I'm sure the book that I am working out of will eventually tackle this issue. However, it is driving me crazy (can't stand my code to look crammed together and cluttered.) Thanks for the help.

Kind of worded that funny.

For example in C/C++ you could do #include "fileName I want to refer to"
I'm just asking for the java equivalent.

pinsickle
Junior Poster in Training
75 posts since Sep 2009
Reputation Points: 27
Solved Threads: 1
 
//In a file called First.java
public class First{
... 
}
//File called Second.java
public class Second{
..
main(){
First f = new First();
}

}


Put the classes in a package together... then you can create a new Object and use the class's methods.

BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You