I’m a C++ programmer learning Java, and I’m having a couple of logistical issues. I was able to recreate the standard “Hello, world!”, but now I need to implement a class (well, besides the fact the the Hello program is in a class, too…Java is weird) and test it.
I defined a small class called Node with a couple of integer fields and a simple member function (in Node.java), so my silly question is, “How do I create a place to try it out in another file?” (It’s remarkable how so many sources seem to assume that you know these little details)
I’m assuming I’ll need a Main.java, with a class Main inside it…plus a “public static void Main(..” method. But how do I access this node class, which is in the same directory? Java doesn’t seem to have “#include” …
If the
Nodeclass andMainclass exist within the same package, then you don’t need to specify animportfor the class. All classes in the same package are automatically included (more or less).If the
NodeorMainare in different packages, then you need to useimport.So, if
Nodewas inawesome.nodepackage, you’re code would look more like…I’d take a closer look at the Packages trail