Shunmuga Gomathy.V
Shunmuga Gomathy.V

Reputation: 19

Ternary operator with narrowing concept

Why the following statements show an error while compiling

 int a=10,b=20;   
   byte c=(a<b)?40:50;
   System.out.println(c);

Upvotes: 2

Views: 64

Answers (1)

Nam Tran
Nam Tran

Reputation: 62

b is already declared.

You can try

int a=10,b=20;   
byte c=(byte) ((a<b)?40:50);
System.out.println(c);

Upvotes: 3

Related Questions