Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

The expression 127 is not of type short - rather it is of type int .

If you want to have an expression of type short , use (short) 127 , as in:

Overloaded o = new Overloaded((short)127);

Then your example will work.

Just a word of caution: short values are limited to -32768 to +32767 meaning that e.g. (short)32768 will result in -32768 – Moonlit Jun 14, 2016 at 5:47

All numeric constants are by default of integer type, and when you want to save integer to byte/short field you need to do a narrowing conversion using cast:

(byte)127
(short)127

Or in your case:

Overloaded o = new Overloaded((byte)127);

Or if you want to short:

Overloaded o = new Overloaded((short)127);

The above code wont produce an error. It would rather show an output- con 3 is called. Short type can be called in a constructor. Typecast it to short

Overloaded o = new Overloaded((short)127);
                for a better answer, try to explain more. Why it won't produce an error, and why your answer would work.
– JLT
                Jun 14, 2016 at 5:55