I've just started to programming in Java, I’m using the book Head First Java to learn how to program. The book explains that for this moment I can use a testclass to test my created class.
My question: how does the testclass know where to find my created class when using a reference variables to access the created variables? See code examples below.
Both files compile without any problem but I fail to see how they link / work together. I'm really curious. Thank you for your time, Dutchy'91.
Post by:Jeanne Boyarsky
Welcome to CodeRanch! I added code tags to your post to make it easier to read.
In Java, all code goes in a package. If you don't specify one, it goes in the default package. Both of your classes are in the default package.
Java also has concept called a classpath. The default is class files in the current directory. You can automatically refer to classes in the classpath in the same package without doing anything.
Putting this together, it means you can refer to classes in the same directory if both are in the default package without having to do anything special. Which is a nice default! It lets people new to Java start without having to be aware of either of these concepts.
Post by:Rute Fischer
Thank you for your clear explanation. It makes more sense to me now how the referencing works 'under the hood' when executing my class file.
Again, thank you for your time!
This thread has been viewed 440 times.
All times above are in ranch (not your local) time.
The current ranch time is Sep 24, 2018 04:15:42.