Multiple choice technology programming languages

The number of characters in an object of a class String is given by?

  1. The member variable called length

  2. The method length() returns the number of characters.

  3. The member variable called size

  4. The method size() returns the number of characters.

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

In Java, String objects use the length() method to return the character count, not a member variable. This is because String is a class - not a primitive or struct - so it encapsulates its data and exposes methods like length() rather than public fields. Option D's size() method doesn't exist for String.