overload and override which happens when : compile or runtime
Overload and Override: which one happens at开发者_StackOverflow社区 compile time and which one at runtime?
It depends on which language you're using, and how you're using it.
For example, in Java the overload resolution is always performed at compile-time, with override resolution is performed at execution time.
In C# that's still normally true - but if you're using C# 4's dynamic typing feature, overload resolution is performed at execution time too:
static void Foo(int y) {}
static void Foo(string y) {}
...
dynamic x = 10;
Foo(x); // Calls Foo(int)
x = "hello";
Foo(x); // Calls Foo(string)
There are plenty of other languages which behave dynamically too. So you really need to learn the behaviour of the language you're using at the time.
Overload -> Compile time Override -> Runtime
精彩评论