Hello,
I am currently studying the topic 'Methods and Encapsulation' from Jeanne Boyarsky and Scott Selikoff.
Now, I tried the following snippets of code :
Case 1 :
Case 2:
Now, when I compile these classes, in Case 1, it works fine and I get the output as :
From method m1...returning short to int
In case 2, however, I get a compile -time error :
error: incompatible types : possible lossy conversion from int to short
short num = m1();
Am failing to understand, if it is promoting the returned short value in case 1, why is it not working in Case 2.
Can anybody please provide a logical explanation for the same?
Help will be appreciated as always
Thank you in anticipation.