It’s not possible to invoke a method on a
String literal. E.g.,
"Hi".length() does not work.
One cannot invoke methods on String literals
One can invoke methods on String literals
CorrectionHere is what's right.
String literal denotes a
String object. One can invoke methods on it like one can invoke methods on any
String object. All the following are correct:
int a = "Hi".length(); int b = new String("Hey").length(); String s = "Ho"; int c = s.length();