Why can't methods have the same name in the same class?

85 Views Asked by At

You can't have methods with the same name in the same class in Smalltalk. Why?

I don't understand why methods can't have same name in same class.

1

There are 1 best solutions below

0
James Foster On

You are probably thinking about function overloading in languages like C++ in which you can have multiple functions/methods with the same name but different parameter types or count. The difference is that in dynamic programming languages like Smalltalk the type is associated with the object not the variable and so a variable can hold any type and the compiler doesn't know the type. So there would be no way to distinguish between functions/methods with the same name.