I came across below java line and puzzled about its output. Can you please explain me logic behind this code
System.out.println((int)(char)(byte) -1);
Output:
65535
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well, it’s equivalent to:
Really the explicit conversion to
intin the original is only to make it callSystem.out.println(int)instead ofSystem.out.println(char).I believe the
bytetocharconversion is actually going through an implicit widening conversion first – so it’s like this really:Does that help at all?