Consider an unknown language with integer and real types in which 1+2, 1.0+2, 1+2.0, and 1.0+2.0 are all legal expressions.
Answers :-
a). 1+2 if they are defined like : int x,y,z; z=x+y ; z=3
Here we didn't use explicit type conversion therefore the result is of coercion without overloading.
b).Let two numbers where 1.0 is floating and 2 is integer
Explicit conversion is called when converting integer to float then in integer so using no coersion , the result of overloading should be 1.0+2.0
c).2.0 is float so it implicit into with 1 integer then 1.0+2.0 is convert implicit type conversion ,so it follows both operator overloading as well as coercion.
d). 1 and 2.0 are converting same type so it follows the adhoc sub type of polymorphism.
Get Answers For Free
Most questions answered within 1 hours.