In C++ I can't use a method if I declare it after the calling method.
Does this order matter in other languages like Java or C#?
In C++ I can't use a method if I declare it after the calling method.
Does this order matter in other languages like Java or C#?
The order of methods/constructors does matter in Java in some corner cases:
No .
It doesn't in C#.
neither C# nor Java does.
Declaration order of methods never matters in C# or Java. Likewise it doesn't matter whether you declare a method before or after a variable that it uses.
Declaration order of variables can matter, however, when they're initialized one depends on another. For example (C#):
but:
Java prevents this exact situation, but it's easy to mimic:
In C# things become even more confusing when you involve partial classes. Initialization occurs in textual order in C#, but that order isn't fully defined when you have multiple files contributing to the same class.
Needless to say, avoid this wherever you possibly can!
There is one tricky case where lexically the function to be called can be declared after the point of call, but not semantically. This is because the class is deemed to be completely defined in the body of the class member functions.