exam questions

Exam 1z0-808 All Questions

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

Exam 1z0-808 topic 1 question 224 discussion

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

Given the content from the Tree.java and Plant.java files:
and the code fragment:
9. Plant t = new Plant();
10. /* insert code fragment here */
Which code fragment is valid at line 10?

  • A. t.m1();
  • B. t.m1(); t.m3();
  • C. t.m1(); t.m3(); t.m4();
  • D. t.m1(); t.m4();
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
iSnover
Highly Voted 2 years, 3 months ago
Selected Answer: B
An erratum to my previous answer, the answer is B as a protected method can be accessed from another package ONLY if it is a subclass. Answer A is also correct but B is more complete, just in case it is better to always mark the "most correct answer".
upvoted 6 times
...
carloswork
Highly Voted 2 years, 2 months ago
Selected Answer: B
Answer is B. To Test (attention to test in different packages and files, as stated): ---------------------------------------------------------------- package branch; import root.*; public class Plant extends Tree { public static void main(String[] args) { Plant t = new Plant(); t.m1(); // Answer A --- Ok, but incomplete. t.m1(); t.m3(); // Answer B --- Ok t.m1(); t.m3(); t.m4(); // Answer C --- Error t.m1(); t.m4(); // Answer D --- Error } } ------------------------- package root; public class Tree { public void m1() {} private void m2() {} protected void m3() {} void m4() {}; } ----------------------------------------------------------------
upvoted 5 times
...
MPignaProTech
Most Recent 2 months, 2 weeks ago
Selected Answer: B
A/B are valid but if I have to choose one I will choose B
upvoted 1 times
...
iSnover
2 years, 3 months ago
Selected Answer: A
The correct answer is A, the methods "m2" and "m3" cannot be seen by the child class because even inheriting it is in a different package, the same occurs for "m4", because when visibility is not placed, it is put automatically the "default" visibility which is even more restricted than private, so it cannot be seen by the "Plant" class, the only method that can be instantiated is "m1", because it is the only one seen.
upvoted 2 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