exam questions

Exam 1z0-809 All Questions

View all questions & answers for the 1z0-809 exam

Exam 1z0-809 topic 1 question 6 discussion

Actual exam question from Oracle's 1z0-809
Question #: 6
Topic #: 1
[All 1z0-809 Questions]

Given:
public class Counter {
public static void main (String[ ] args) {
int a = 10;
int b = -1;
assert (b >=1) : "Invalid Denominator";
int Ñ = a / b;
System.out.println (c);
}
}
What is the result of running the code with the ""ea option?

  • A. -10
  • B. 0
  • C. An AssertionError is thrown.
  • D. A compilation error occurs.
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
MPignaProTech
1 month, 4 weeks ago
Selected Answer: C
C is a good answer
upvoted 1 times
...
asdfjhfgjuaDCV
10 months ago
C is the answer
upvoted 1 times
...
shivkumarx
10 months, 1 week ago
Selected Answer: C
Correct answer is C assuming question and code have typos
upvoted 1 times
...
steefaand
11 months, 1 week ago
Selected Answer: C
Assuming there are two typos: 1. int Ñ = a / b; is actually int c= a/b 2. java ""ea is actually java -ea Answer is C.
upvoted 2 times
...
push05
1 year ago
C:\cjava\809>javac Counter.java C:\cjava\809>java -ea Counter Exception in thread "main" java.lang.AssertionError: Invalid Denominator at Counter.main(Counter.java:5) C:\cjava\809>java -da Counter -10
upvoted 2 times
...
Temilaw25
1 year, 7 months ago
Correct answer is C. The moment assertion is enabled, this happens: In the code, the condition in the assert statement is b >= 1. This condition is false because b is assigned the value -1. Therefore, when the JVM encounters this assert statement (with assertions enabled via the "ea" option), it throws an AssertionError with the message "Invalid Denominator". Assertions are disabled by default in Java. The "ea" option is a command-line switch that can be used to enable assertions during program execution.
upvoted 4 times
...
Kim514
1 year, 10 months ago
Answer is A -ea to enable assertions With this option, assertions can be enabled (by default, they are turned off). In a language that supports assertions, the programmer can add runtime conditional checks. In Java, this is done by adding an assert statement, followed by a condition. When assertions are disabled, these statements are ignored completely, but when enabled, the JVM throws an error if the condition turns out to be false. This can be used to check whether the program works as expected. An example of an assert statement in Java: int i = 25; assert i < 24; When assertions are enabled with the -ea option, the preceding code will result in a java.lang.Error instance thrown by the JVM once the assert statement runs. When not explicitly specified ...
upvoted 2 times
Kim514
1 year, 10 months ago
Correct answer is C! (sorry)
upvoted 3 times
...
...
r1muka5
1 year, 10 months ago
Answer is D. Compilation error - since c is not declared. There is no way this code block would get compiled if copied/pasted to console.
upvoted 1 times
...
dexdinh91
2 years, 3 months ago
A, tested in console
upvoted 2 times
dexdinh91
2 years, 3 months ago
""ea is not -ea
upvoted 1 times
...
...
WilsonKKerll
2 years, 10 months ago
Use -ea option: java -ea className Answer is C.
upvoted 3 times
...
9641
3 years ago
Selected Answer: A
int c = a / b;
upvoted 2 times
...
akitravv
3 years, 8 months ago
D. Compilation error - since c is not declared. System.out.println(Ñ); gives -10 as output
upvoted 3 times
...
Svetleto13
3 years, 8 months ago
A,tested
upvoted 1 times
Svetleto13
3 years, 8 months ago
Correct answer is C,because assertions are enabled.If they are disabled answer is A.There is one more thing - int = a/b needs to be changed to int c = a/b ,if not,leads to compilation error,
upvoted 7 times
...
...
lxl
3 years, 8 months ago
A, tested
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago