125k views
1 vote
Which of the following statements refers to the second character in a String object named address?

a. char c = address(1);
b. char c = address(2);
c. char c = address[1];
d. char c = address[2];

User Aleksandar
by
8.7k points

1 Answer

4 votes

Final answer:

The second character in a String object named 'address' is accessed with the syntax 'address[1]' where indices start at 0; thus, the correct statement is option c.

Step-by-step explanation:

The question asks which of the following statements refers to the second character in a String object named address. In many programming languages, such as Java, indexing of arrays and strings starts at 0. Therefore, to access the second character, you would need to use index 1. The correct way to refer to the second character in the string object named address would be through the use of square brackets and the appropriate index as shown in option c: char c = address[1];

User Hongbo Miao
by
7.3k points