Access to other class files in Java

We just started learning Java for my degree, and I was given a folder with various Java classes, each in its own .java file, with the file name matching the name of the class that it has in.

There is one file that hosts an open class that has the following:

public static void main(String[] args) {}

This creates a new instance of another class, which is stored in a separate .java file, and many of the classes (each in its own .java file) seem to refer to other classes without putting anything, for example

include("otherclass.php")

If you work in PHP.

My question is: Is this what Java does? So you can happily access other classes and create new instances of the class from another .java file if they are in the same directory?

Hope my question makes sense!

Thank,

Jack.

+3
3

import. . - , / JAR . import , , ( , ), ,

com.example.OtherClass otherClass = new com.example.OtherClass();

, java.lang , .

. :

+5

, .

java, , , ,

public class Whatever{
    enter code here
}

,

Whatever we = new Whatever();
0

BalusC .

Java "CLASSPATH", , .class , . , CLASSPATH, . CLASSPATH , .

Java IDE CLASSPATH. , .

-1

Source: https://habr.com/ru/post/1778559/


All Articles