About Question enthuware.ocajp.i.v7.2.1109 :

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

Moderator: admin

Post Reply
Venceslas
Posts: 15
Joined: Thu Feb 05, 2015 3:50 pm
Contact:

About Question enthuware.ocajp.i.v7.2.1109 :

Post by Venceslas »

The explanation said: "StringBuilder extends Object".

It seems to me that is AbstractStringBuilder.

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

Re: About Question enthuware.ocajp.i.v7.2.1109 :

Post by admin »

Explanation is correct - http://docs.oracle.com/javase/7/docs/ap ... ilder.html

Where did you see it extending AbstractStringBuilder?
If you like our products and services, please help us by posting your review here.

Venceslas
Posts: 15
Joined: Thu Feb 05, 2015 3:50 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1109 :

Post by Venceslas »

When I browse the class StringBuilder in my eclipse environnement for example I can see that. Now I must admit your argument is strong ;)

By looking deeper, it seems AbstractStringBuilder is not a public class in the package java.lang, so it is probably the reason why the javadoc does not mention that.

I think my JDK is a oracle one, but if you don't have the same code, I may have need to check it.

Venceslas
Posts: 15
Joined: Thu Feb 05, 2015 3:50 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1109 :

Post by Venceslas »

Could you check in source code please due to my explanation please?

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

Re: About Question enthuware.ocajp.i.v7.2.1109 :

Post by admin »

Yes, it is probably because AbstractStringBuilder is private. But that is ok. As far as the users of the class StringBuilder are concerned, they are not aware of the existence of AbstractStringBuilder. It is good to have this discussion linked to the question.
If you like our products and services, please help us by posting your review here.

winddd
Posts: 18
Joined: Wed Feb 11, 2015 10:48 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1109 :

Post by winddd »

Which of the following statements are true?
Please select 2 options

1) Method length() of String class is a final method.
2) You can make mutable subclasses of the String class.
3) StringBuilder extends String.
4) StringBuilder is a final class.
5) String class is not final.

Here only one veracious statement, #4.

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

Re: About Question enthuware.ocajp.i.v7.2.1109 :

Post by admin »

Methods of a final class are implicitly final. So option 1 is valid as well.
If you like our products and services, please help us by posting your review here.

winddd
Posts: 18
Joined: Wed Feb 11, 2015 10:48 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1109 :

Post by winddd »

It is very, very, very disputable from the point of view of the people who got used to accurate information (programmers). "Final method" means "method declaration contains _final_ modifier", not anything else.

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

Re: About Question enthuware.ocajp.i.v7.2.1109 :

Post by admin »

winddd wrote:It is very, very, very disputable from the point of view of the people who got used to accurate information (programmers). "Final method" means "method declaration contains _final_ modifier", not anything else.
Agreed but in the category of splitting hair. As per Section 8.4.3.3 of JLS:
A private method and all methods declared immediately within a final class (§8.1.1.2) behave as if they are final, since it is impossible to override them.
If you like our products and services, please help us by posting your review here.

mrmuiz
Posts: 49
Joined: Mon Jul 27, 2015 4:34 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1109 :

Post by mrmuiz »

Came here for winddd's same reason. I think it's wrong saying that
method length() of String class is a final method.
You can say that here

Code: Select all

interface I{int a=0;}
I has a final variable but, as already quoted, 8.4.3.3 of JLS states:
A private method and all methods declared immediately within a final class (§8.1.1.2) behave as if they are final, since it is impossible to override them.
And 8.1.1.2 simply says:
Because a final class never has any subclasses, the methods of a final class are never overridden
and nothing more.
To me it's like saying that here

Code: Select all

class A{private void a(){}}
a() is final just because it behaves like if it was, being not possible to override it.

elias86
Posts: 7
Joined: Fri May 04, 2018 4:14 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1109 :

Post by elias86 »

How can I know if a Class is final (eg. String) ? What class i must know for the exam???

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

Re: About Question enthuware.ocajp.i.v7.2.1109 :

Post by admin »

There are several final classes in Java standard library. For the purpose of the exam, you need to memorize that all primitive wrapper classes(Integer, Double, Boolean, Character etc), String, StringBuilder, and all date/time related classes (i.e. LocalDate, LocalTime, LocalDateTime, Period, and Duration etc.) are final.
If you like our products and services, please help us by posting your review here.

st.lisker
Posts: 22
Joined: Sat Jun 30, 2018 6:11 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1109 :

Post by st.lisker »

Hi. '' Because a final class never has any subclasses, the methods of a final class are never overridden ''
So how can I to override toString() method?

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

Re: About Question enthuware.ocajp.i.v7.2.1109 :

Post by admin »

I am not sure I understand your question but a final class is allowed to override methods of its super class, so there is no problem for a final class to override toString.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 56 guests