Java Reference
In-Depth Information
Display 7.8
Use of the EnhancedStringTokenizer Class (part 2 of 2)
9 EnhancedStringTokenizer wordFactory =
10 new EnhancedStringTokenizer(sentence);
11 System.out.println("Your sentence with extra blanks deleted:");
12 while (wordFactory.hasMoreTokens())
13 System.out.print(wordFactory.nextToken() + " ");
14 System.out.println();
15
//All tokens have been dispensed .
16 System.out.println("Sentence with each word on a separate line:");
17 String[] token = wordFactory.tokensSoFar();
18
for ( int i = 0; i < token.length; i++)
19 System.out.println(token[i]);
20 }
21 }
Sample Dialogue
Enter a sentence:
I love you, madly.
Your sentence with extra blanks deleted:
I love you, madly.
Sentence with each word on a separate line:
I
love
you,
madly.
7.2
Encapsulation and Inheritance
Ignorance is bliss.
PROVERB
This section is a continuation of Section 7.1 and uses the same example classes we
used there. In this section, we consider how the information-hiding facilities of Java,
primarily the private modifier, interact with inheritance.
 
 
 
Search WWH ::




Custom Search