#OOPs

14 messages · Page 1 of 1 (latest)

eager acorn
#

Why doesn't line number 17 give print Short?
it was printing int, and I can't understand why.

quartz bladeBOT
#

This post has been reserved for your question.

Hey @eager acorn! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

spiral glacier
#

looks like since you declared primitive short, primitive method argument is preferred over wrapper

eager acorn
spiral glacier
#

because short to int conversion isnt lossy

#

long > int > short

#

you can up cast but not downcast

#

/run

int x = 4;
short y = x;
knotty kestrelBOT
#

@spiral glacier I only received java(15.0.2) error output

file0.code.java:3: error: incompatible types: possible lossy conversion from int to short
short y = x;
          ^
1 error
error: compilation failed
spiral glacier
#

but reverse is fine

#

/run ```java
short x = 4;
int y = x;

knotty kestrelBOT
#

Your java(15.0.2) code ran without output @spiral glacier

eager acorn