What is the point of creating a class object to call a method in another file when I can just call the file and do the exact same thing?
What I've seen and been taught is that in order to call a method from another file you need to make a class object first, then you call the method using the object
Say you have a method in "FileTwo"
public class FileTwo
{
public static void method
{
}
}
So if I wanted to call "method" in another file, "FileOne" I'd call it like this
public class FileOne
{
FileTwo file = new FileTwo;
public static void main(String[] args)
{
file.method();
}
}
But I'm able to do the same thing just by calling the file itself
public class FileOne
{
public static void main(String[] args)
{
FileTwo.method();
}
}
So what's the point of creating the class object?