i have two methods whose name are the same,and since they are in the same class so oberloading would takes place.But if i have methods defined as follows class dummy{ void Firstfunc(int a,int b,int c) { ....................... } float Firstfunc(int a,int b,int c) { ........................ } } since it is clear that the the diference in two methods is only of return type can anybody tell me that is it possible?
Anbooo Sanygao
Ranch Hand
Joined: Oct 04, 2000
Posts: 45
posted
0
Did you try writing a small piece of code
ravi chan
Greenhorn
Joined: Nov 02, 2000
Posts: 11
posted
0
class dummy{ void Firstfunc(int a,int b,int c) { ....................... } float Firstfunc(int a,int b,int c) { ........................ } }
it is not possible, in order to overload the method signature has to be different. So change the arguments to : float Firstfunc(float a, int b, int c). Return type can be any data type when you are overloading. Please correct me if I am wrong. And also a thing to note is you cannot change the overloaded declaration to float Firstfunc(long a, long b, long c) will give you a compiler error if your method call is Firstfunc(1, 2, 3) because the compiler gets confused about both the overloaded methods.
Gautam Pandya
Greenhorn
Joined: Sep 29, 2000
Posts: 17
posted
0
Ravi, Your explanation is really good but I think the last part as quoted under is not correct. The method can be overloaded with a method float Firstfunc(long a, long b, long c). I mean, there is nothing wrong with the given code if modified as below.
Gautam.
Originally posted by ravi chan: . . . And also a thing to note is you cannot change the overloaded declaration to float Firstfunc(long a, long b, long c) will give you a compiler error if your method call is Firstfunc(1, 2, 3) because the compiler gets confused about both the overloaded methods.
prasanthi kothapa
Ranch Hand
Joined: Oct 19, 2000
Posts: 30
posted
0
hi ameen, changing the return type doesn't come under overloading, since the signature of the method doesn't change(only the method name and arguments come under the signature). hence you will get a compiler error in this case. hope it helps.. prasanthi
Oliver Grass
Ranch Hand
Joined: Nov 02, 2000
Posts: 65
posted
0
Hey Ravi, you can overload the method with a signature Firstfunc(long a, long b, long c).
Originally posted by ravi chan: And also a thing to note is you cannot change the overloaded declaration to float Firstfunc(long a, long b, long c) will give you a compiler error if your method call is Firstfunc(1, 2, 3) because the compiler gets confused about both the overloaded methods. [/B]
Compiler will not get confused, cause Firstfunc(1, 2, 3) can be uniquely identified. 1, 2, 3 are ints, so he will call the Firstfunc(int a, int b, int c)... Same with floats and doubles.... hope that helps Oliver