exam questions

Exam 1z0-808 All Questions

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

Exam 1z0-808 topic 1 question 100 discussion

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

Given:

What is the result?

  • A. Compilation fails at line n3 and line n4.
  • B. Compilation fails at line n1 and line n2.
  • C. Welcome Visit Count:1 Welcome Visit Count: 1
  • D. Welcome Visit Count:1 Welcome Visit Count: 2
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

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
3 months ago
Selected Answer: B
count is declared as package-private but bot static, you cannot do count++; or count = anyValue. Correct answer is B
upvoted 1 times
...
DarGrin
1 year, 3 months ago
Selected Answer: B
B is a answer
upvoted 1 times
...
IbrahimAlnutayfi
1 year, 6 months ago
Selected Answer: B
The answer is B
upvoted 1 times
...
eilla
2 years, 1 month ago
Correct answer is B. A static method can only reference other static methods and static fields. Count is non static and therefore produces "error: non-static variable count cannot be referenced from a static context" I initially thought App.displayMessage() was the issue because an app object hadn't been instantiated. However here app is not an object but rather a class reference to a static method. Static fields do not need an object of that class in order to be used. This error could also be fixed by making displayMessage non static and creating an app object to reference the method from in main public class App { int count; public static void displayMessage() { count++; System.out.println("Welcome. Visit count: " + count); } public static void main(String[] args) { App.displayMessage(); App.displayMessage(); } }
upvoted 2 times
...
iSnover
2 years, 3 months ago
Selected Answer: B
Correct B is Answer. Because you cannot make a static reference to the non-static field count. To make codes complie need to change "count" into a static variable as "static int count".
upvoted 3 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