exam questions

Exam 1z0-829 All Questions

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

Exam 1z0-829 topic 1 question 50 discussion

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

Given the code fragment:

What is the result?

  • A. Cat -
    Dog
  • B. Cat -
    Cat
  • C. Dog -
    Dog
  • D. A NullPointerException is thrown.
  • E. Cat -
    null
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
SrinivasJasti
2 weeks, 1 day ago
Selected Answer: B
p and p1 both point to the same Pet object that has the name "Dog" if p1.name changes the p.name also is same as p1.name as they reference same object, so p =p1 in the 4th lines has no significance and when p is set to null the reference of p1 does not change so answer is Cat Cat
upvoted 1 times
...
9817c20
2 months, 1 week ago
Yep its B!
upvoted 1 times
...
xplorerpj
6 months, 3 weeks ago
Selected Answer: B
B is correct answer
upvoted 1 times
...
james2033
11 months ago
Selected Answer: B
package q50; public class Q50 { public static void main(String[] args) { Pet p = new Pet("Dog"); Pet p1 = p; p1.name = "Cat"; p = p1; System.out.println(p.name); p = null; System.out.println(p1.name); } } class Pet { public static String name; public Pet(String name) { this.name = name; } public String name() { return name; } public void setName(String name) { this.name = name; } } // Result: // Cat // Cat
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