exam questions

Exam 1z0-808 All Questions

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

Exam 1z0-808 topic 1 question 226 discussion

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

Given the code fragment:

You want the code to print:

Sold: 5 items. Stock in Hand: 5 -
Purchased: 5 items. Stock in Hand: 10?
Which action enables the code to print this?

  • A. Declare the stock variable and the purchase(), sell(), and printStock() methods static.
  • B. Declare the stock and qty variables and purchase()and sell()methods static.
  • C. Declare the stock and qty variables and the printStock() method static.
  • D. Declare the stock and qty variables static.
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
carloswork
2 months, 1 week ago
Selected Answer: C
As below.
upvoted 2 times
...
carloswork
2 months, 1 week ago
Correct, Aswer is C. To test: public class StockRoom { private int stock = 10; // declare as static private int qty; // declare as static public void purchase(int q) {stock += q; this.qty = q;} public void sell(int q) {stock -= q; this.qty = q;} public void printStock(String action ) { declare as static System.out.println(action + ":" + qty + " items. Stock in Hand: " + stock); } public static void main (String[] args) { StockRoom k1 = new StockRoom(); k1.sell(5); StockRoom.printStock("Sold"); StockRoom k2 = new StockRoom(); k2.purchase(5); StockRoom.printStock("Purchased"); } }
upvoted 4 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