About Question enthuware.ocajp.i.v7.2.1109 :
Moderator: admin
-
- Posts: 15
- Joined: Thu Feb 05, 2015 3:50 pm
- Contact:
About Question enthuware.ocajp.i.v7.2.1109 :
The explanation said: "StringBuilder extends Object".
It seems to me that is AbstractStringBuilder.
It seems to me that is AbstractStringBuilder.
-
- Site Admin
- Posts: 10074
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1109 :
Explanation is correct - http://docs.oracle.com/javase/7/docs/ap ... ilder.html
Where did you see it extending AbstractStringBuilder?
Where did you see it extending AbstractStringBuilder?
If you like our products and services, please help us by posting your review here.
-
- Posts: 15
- Joined: Thu Feb 05, 2015 3:50 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1109 :
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.
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.
-
- Posts: 15
- Joined: Thu Feb 05, 2015 3:50 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1109 :
Could you check in source code please due to my explanation please?
-
- Site Admin
- Posts: 10074
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1109 :
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.
-
- Posts: 18
- Joined: Wed Feb 11, 2015 10:48 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1109 :
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.
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.
-
- Site Admin
- Posts: 10074
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1109 :
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.
-
- Posts: 18
- Joined: Wed Feb 11, 2015 10:48 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1109 :
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.
-
- Site Admin
- Posts: 10074
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1109 :
Agreed but in the category of splitting hair. As per Section 8.4.3.3 of JLS: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.
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.
-
- Posts: 49
- Joined: Mon Jul 27, 2015 4:34 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1109 :
Came here for winddd's same reason. I think it's wrong saying that I has a final variable but, as already quoted, 8.4.3.3 of JLS states:
To me it's like saying that herea() is final just because it behaves like if it was, being not possible to override it.
You can say that heremethod length() of String class is a final method.
Code: Select all
interface I{int a=0;}
And 8.1.1.2 simply says: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 nothing more.Because a final class never has any subclasses, the methods of a final class are never overridden
To me it's like saying that here
Code: Select all
class A{private void a(){}}
-
- Posts: 7
- Joined: Fri May 04, 2018 4:14 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1109 :
How can I know if a Class is final (eg. String) ? What class i must know for the exam???
-
- Site Admin
- Posts: 10074
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1109 :
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.
-
- Posts: 22
- Joined: Sat Jun 30, 2018 6:11 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1109 :
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?
So how can I to override toString() method?
-
- Site Admin
- Posts: 10074
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1109 :
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.
Who is online
Users browsing this forum: No registered users and 16 guests