Discussion
Which line contains the error?
package com.acme.core;
public class Sample46
{
public static void main(String[] args)
{
int stock = -1;
assert stock >= 0 : stock;
System.out.println(stock);
}
}
Answer: B
Nothing is wrong with the code. The mistake people make with it is at the command line: running java -ea:com.acme... com.acme.core.Sample46 enables the check, but -ea:com.acme.core without the three dots names a CLASS, and no class has that name, so assertions stay off and the negative stock passes unnoticed.
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