About Question enthuware.ocajp.i.v8.2.1429 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
flex567
Posts: 202
Joined: Mon Apr 02, 2018 8:40 am
Contact:

About Question enthuware.ocajp.i.v8.2.1429 :

Post by flex567 »

How many LocalDate objcts were created during this statement?:

Code: Select all

java.time.LocalDate dt = java.time.LocalDate.parse("2015-01-01").minusMonths(1).minusDays(1).plusYears(1);
I would say only 1, from the parse method.

Online
admin
Site Admin
Posts: 10045
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1429 :

Post by admin »

And what about the chained method calls .minusMonths(1).minusDays(1).plusYears(1); ?
If you like our products and services, please help us by posting your review here.

flex567
Posts: 202
Joined: Mon Apr 02, 2018 8:40 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1429 :

Post by flex567 »

Don't they work on the same reference?

Online
admin
Site Admin
Posts: 10045
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1429 :

Post by admin »

This is what the explanation says,
Observe that most of the methods of LocalDate (as well as LocalTime and LocalDateTime) return an object of the same class. This allows you to chain the calls as done in this question. However, these methods return a new object. They don't modify the object on which the method is called.
You might want to go through "Creating a date/time object using an existing date/time object" paragraph of Section 12.3.2 Creating date/time objects from OCAJP Fundamentals book by Hanumant Deshmukh..
If you like our products and services, please help us by posting your review here.

flex567
Posts: 202
Joined: Mon Apr 02, 2018 8:40 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1429 :

Post by flex567 »

So this is like with String class.
And not like with StringBuilder class.

How do you know if a method returns a new object or modifies the existing from Java API documentation?

Online
admin
Site Admin
Posts: 10045
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1429 :

Post by admin »

Yes, from the javadoc API description.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: admin and 53 guests