0
In Java is it possible/correct to call a method before it is declared?
public static void main(String[] args) { hello(); } static void hello() { System.out.println(āhiā); } In the example above, it looks as though the method āhelloā was called on the second line before it was declared two lines down. Is it okay?
5 Answers
+ 8
Š¦Š°ŃŃ Š”ŠŠŠŠŠ - ŠŠ¾Š³Š³Š¾ I
My pleasure... š
I think many people share the same understanding as your earlier comment and so I thought it would be helpful for me to show a simple demo. š
+ 6
Š¦Š°ŃŃ Š”ŠŠŠŠŠ - ŠŠ¾Š³Š³Š¾ I What do you mean it's not possible in Python?
There are two such scenarios that come to mind where similar behavior can exist in Python.
First, the order doesn't matter within class methods.
Second, a similar main() function can be created to simulate a single entry point as seen in Java.
Here's a little demo I put together to demonstrate:
https://code.sololearn.com/c4AAaU6pWLwa/?ref=app
+ 3
Yes it is possible in Java.