I have noticed that you can call a function in java before defining it, just like Javascript. Now I know that Javascript supports function hoisting because of which it is possible to do so, but what about Java, for ex
public class Sample_class {
public void sample_meth1()
{
sample_meth2(); //calling before defining
}
public void sample_meth2() //Function Definition
{
}
}
The same goes for main method, where you can call a method before it has been declared and defined. Why and How?
I was expecting a compile time error, but it executed successfully.
In Java, the order of the methods doesn't matter. You can call a method from any other method, even though one method is defined before the other.