exam questions

Exam 1z0-819 All Questions

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

Exam 1z0-819 topic 1 question 120 discussion

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

Given:



How many LocalDate objects are created in this example?

  • A. 2
  • B. 3
  • C. 4
  • D. 5
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️

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
ASPushkin
3 weeks ago
Selected Answer: D
create object it doesn't mean that you must have a reference to it LocalDate is an immutable date-time object So LocalDate d1 = LocalDate.now(); //1 d1.plusDays(1); //1 d1 = d1.minusMonths(2); //1 LocalDate d2 = d1.plusWeeks(3); //1 d2.minusDays(4); //1 d2 = null; 1+1+1+1+1=5 objects created
upvoted 1 times
...
cathDev
2 months, 2 weeks ago
Selected Answer: B
LocalDate ld = LocalDate.now(); create 1st d1 = d1.minusMonths(2); 2nd LocalDate d2 = d1.plusWeeks(3); 3rd
upvoted 1 times
...
d7bb0b2
6 months ago
A: LocalDate ld = LocalDate.now(); - This line creates the first LocalDate object, which represents the current date. LocalDate ld2 = ld.plusWeeks(3); - This line creates the second LocalDate object. The plusWeeks method returns a new LocalDate object that represents the date three weeks after the date in ld. The other methods called on ld and ld2 (plusDays, minusMonths, minusDays) also return new LocalDate objects, but these are not assigned to any variables, so they are not accessible after the method call and are eligible for garbage collection.
upvoted 1 times
d7bb0b2
5 months ago
Correction: B = 3 => null line and d1.plus... not is asigned so no count
upvoted 1 times
...
...
duydn
7 months ago
Selected Answer: B
B. 3 Explanation: 1. Initially, d1 is assigned the current date using LocalDate.now(), creating the first LocalDate object. 2 d1.plusDays(1) returns a new LocalDate object that is one day ahead of d1. However, this new object is not assigned to any variable, so it is not counted as a created object. 3. d1 = d1.minusMonths(2) assigns a new LocalDate object that is two months before d1 to d1. This creates the second LocalDate object. 4. d1.plusWeeks(3) returns a new LocalDate object that is three weeks ahead of d1. However, this new object is not assigned to any variable, so it is not counted as a created object. 5. d2.minusDays(4) does not create a new LocalDate object because the return value is not assigned to any variable. 6. d2 = null assigns null to d2, but it does not create a new LocalDate object. Therefore, the total number of LocalDate objects created is 3.
upvoted 1 times
...
APJ1
7 months, 2 weeks ago
Selected Answer: A
Option A is correct
upvoted 1 times
...
RoxyFoxy
7 months, 3 weeks ago
LocalDate is immutable (like String for example) and does not have public constructor but factory methods. When we create an obj, the proprieties cannot change. For example: d1- now... today in other words d1.plusDays(1)...tomorrow (...today is still today) d1.minusMonth(2)...is the same date but two months ago...and so on.
upvoted 1 times
...
RoxyFoxy
7 months, 3 weeks ago
Selected Answer: D
LocalDate d1 = LocalDate.now(); //1 object created with the factory method now() d1.plusDays(1); //1 object created with instance method plusDays() d1 = d1.minusMonth(2); //1 object created with instance method minusMonth() LocalDate d2 = d1.plusWeeks(3); // 1 object with instance method plusWeeks() d2.minusDays(4); // 1 object with instance method minusDays() d2 = null// no object is created.
upvoted 1 times
...
[Removed]
9 months, 2 weeks ago
Selected Answer: D
Apparently I'm the only one answering this. BUT LocalDate is immutable so every method: plusDays(), minusMonths, plusWeeks, minusDays(). ALL return a new LocalDate Object. Resulting in 5 Objects being created. Also d1.plusDays(1) on the second line would do nothing as this return value is not caught.
upvoted 2 times
...
Stavok
10 months, 2 weeks ago
Selected Answer: A
The correct answer is **A. 2**. In this example, two `LocalDate` objects are created. The first one is created when `d1` is initialized with the current date using the `now()` method. The second one is created when `d2` is assigned the value of `d1.plusWeeks(3)`. The other method calls, such as `plusDays(1)`, `minusMonths(2)`, and `minusDays(4)` do not create new objects because the `LocalDate` class is immutable and these methods return new objects instead of modifying the existing ones.
upvoted 1 times
...
Stavok
10 months, 2 weeks ago
Selected Answer: A
The correct answer is **A. 2**. In this example, two `LocalDate` objects are created. The first one is created when `d1` is initialized with the current date using the `now()` method. The second one is created when `d2` is assigned the value of `d1.plusWeeks(3)`. The other method calls, such as `plusDays(1)`, `minusMonths(2)`, and `minusDays(4)` do not create new objects because the `LocalDate` class is immutable and these methods return new objects instead of modifying the existing ones.
upvoted 1 times
...
belal97
11 months ago
i think 3 (80%) b
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