Page 1 of 1

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

Posted: Thu Feb 05, 2015 4:07 pm
by Venceslas
The explanation said: "StringBuilder extends Object".

It seems to me that is AbstractStringBuilder.

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

Posted: Thu Feb 05, 2015 9:07 pm
by admin
Explanation is correct - http://docs.oracle.com/javase/7/docs/ap ... ilder.html

Where did you see it extending AbstractStringBuilder?

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

Posted: Fri Feb 06, 2015 3:13 pm
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.

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

Posted: Tue Feb 10, 2015 1:17 am
by Venceslas
Could you check in source code please due to my explanation please?

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

Posted: Tue Feb 10, 2015 9:11 am
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.

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

Posted: Fri Feb 13, 2015 5:15 am
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.

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

Posted: Fri Feb 13, 2015 6:35 am
by admin
Methods of a final class are implicitly final. So option 1 is valid as well.

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

Posted: Fri Feb 13, 2015 8:09 am
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.

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

Posted: Fri Feb 13, 2015 8:15 am
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.

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

Posted: Tue Jul 28, 2015 9:22 am
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.

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

Posted: Fri May 04, 2018 5:14 am
by elias86
How can I know if a Class is final (eg. String) ? What class i must know for the exam???

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

Posted: Fri May 04, 2018 6:10 am
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.

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

Posted: Sat Jun 30, 2018 4:18 pm
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?

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

Posted: Sat Jun 30, 2018 9:39 pm
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.