Discussion
Which line contains the error?
public class Sample34
{
public static void main(String[] args)
{
char c = 'a';
assert c + 1 == 'b' : "not next";
System.out.println((char)(c + 1));
}
}
Answer: B
This one is fine. Arithmetic promotes the char to int, and the literal 'b' promotes too, so 98 == 98 holds and the assertion passes. The cast on the print is what turns the int back into a char. Nothing here depends on assertions being enabled.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development