Top Posters
Since Sunday
10
p
4
h
4
c
4
d
3
3
c
3
t
3
u
3
A
3
B
3
j
3
New Topic  
rizumidancer rizumidancer
wrote...
Posts: 507
Rep: 6 0
4 years ago
Analyze the following code.

class Test {
public static void main(String[] args) {
StringBuilder strBuf = new StringBuilder(4);
strBuf.append("ABCDE");
System.out.println("What's strBuf.charAt(5)? " + strBuf.charAt(5));
}
}


▸ The program has a compilation error because you cannot specify initial capacity in the StringBuilder constructor.

▸ The program has a runtime error because because the buffer's capacity is 4, but five characters "ABCDE" are appended into the buffer.

▸ The program compiles and runs fine.

▸ The program has a runtime error because the length of the string in the buffer is 5 after "ABCDE" is appended into the buffer. Therefore, strBuf.charAt(5) is out of range.
Textbook 
Introduction to Java Programming, Comprehensive Version

Introduction to Java Programming, Comprehensive Version


Edition: 10th
Author:
Read 58 times
1 Reply
Replies
Answer verified by a subject expert
jenniferagrethejenniferagrethe
wrote...
Posts: 369
4 years ago
Sign in or Sign up in seconds to unlock everything for free
More solutions for this book are available here

Related Topics

rizumidancer Author
wrote...

4 years ago
Correct Slight Smile TY
yen
wrote...

Yesterday
Brilliant
wrote...

2 hours ago
This site is awesome
New Topic      
Explore
Post your homework questions and get free online help from our incredible volunteers
  999 People Browsing
Related Images
  
 95
  
 447
  
 27814
Your Opinion
Which of the following is the best resource to supplement your studies:
Votes: 300

Previous poll results: How often do you eat-out per week?