Which of the following statements are true?
1 ) The String class is implemented as a char array, elements are addressed using the stringname[] convention
2) The + operator is overloaded for concatenation for the String class
3) Strings are a primitive type in Java and the StringBuffer is used as the matching wrapper type
4) The size of a string can be retrieved using the length property
Answer :
2) The + operator is overloaded for concatenation for the String class
In Java Strings are implemented as a class within the Java.lang package with the special distinction that the + operator is overloaded. If you thought that the String class is implemented as a char array, you may have a head full of C/++ that needs emptying. There is not "wrapper class" for String as wrappers are only for primitive types.
If you are surprised that option 4 is not a correct answer it is because length is a method for the String class, but a property for and array and it is easy to get the two confused.
No comments:
Post a Comment