Which lines will not cause compilation errors?
Explanation
Values of the integral types byte, short, int, and long can be created from int literals. Values of type long that exceed the range of int can be created from long literals. Integer literals can be expressed by these number systems:
  • Decimal: Base 10, whose digits consists of the numbers 0 through 9; this is the number system you use every day
  • Hexadecimal: Base 16, whose digits consist of the numbers 0 through 9 and the letters A through F
  • Binary: Base 2, whose digits consists of the numbers 0 and 1 (you can create binary literals in Java SE 7 and later) For general-purpose programming, the decimal system is likely to be the only number system you'll ever use.
However, if you need to use another number system, the following example shows the correct syntax. The prefix 0x indicates hexadecimal and 0b indicates binary:
// The number 26, in decimal
int decVal = 26;
//  The number 26, in hexadecimal
int hexVal = 0x1a;
// The number 26, in binary
int binVal = 0b11010;
Read more: Primitive Data Types

@Cosmo Since the question relies heavily on the size of char, I think it's CRUCIAL to write at the very start of the explanation that char is 0-> 65536, and then you explain how these numbers work. Also you have a question that also uses numbers like here? Except they're considered a wrong answer there? Look into it pls

2023 Feb 16, 3:06:58 AM

@cdeneuve, can you specify please what is wrong exactly? We can improve it

2019 Mar 13, 12:58:35 PM

@StarkBjorn because "-1" not in the range of char. The range of char is: 0 to 65,536 (unsigned)

2019 Mar 13, 12:56:11 PM

The explanation doesn't look right

2018 Oct 29, 5:51:45 AM

But why char c = -1; is wrong?

2018 Jul 22, 9:47:49 AM

@atomshik64 thanks for feedback! added explanation

2018 Feb 2, 5:20:27 PM

There is no explanation in this question at least when you choose wrong answer

2018 Jan 2, 12:18:02 PM

@vimalpanchal char d=0*10000; is correct but char dd=0x10000; is not correct

2017 Jul 19, 7:21:27 AM

but this - char d = 0x1000; works fine ;)

2017 May 18, 12:05:12 AM

@vimalpanchal error: incompatible types: possible lossy conversion from int to char char d = 0x10000; ^ 1 error

2017 May 18, 12:03:28 AM

char d= 0x10000; should be correct right.

2017 Feb 24, 10:08:26 AM

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes