CIS 121 February 9, 2000
Recall Programming Assignment 2.
There are several methods available in the String object that you
may find useful. Let string be a String object.
- string.length() returns the length of the string.
- string.endsWith(s) returns a boolean value of true if string ends with s.
- string.substring(n) returns a substring of string beginning at 0 and ending at position n.
- string.substring(n,m) returns a substring beginning at position n and ending at position m.
- string.replace(char1,char2) replaces all instances of char1 in string with char2.
- string.toUpperCase() returns a string in which each letter is replaced by its uppercase equivalent.
- string.compareTo(s) returns an integer determining whether or not string is alphabetically before, after, or equal to s.
You may eliminate the need for removing duplicates from the arrays you read.
Recall the important concepts we have discussed.
Inheritance - Using the extends clause to create new classes that inherit methods
and variables from other classes.
Polymorphism - Making method calls through different forms.
Other notes about the Object class
- Contains a method toString that is public with return type String and
an empty parameter list that defines how a object is treated if it is used
in the context of a string.
- Contains a method called equals which allows us to compare it to other
objects.
Concrete Method - Methods which have implementations.
Concrete Classes - Classes in which all methods are concrete.
Abstract Method - Methods which have no implementation.
Abstract Classes - Classes in which at least one method is abstract.
One correction about how an abstract method is defined. Instead of
using { ... }, use an ;. For example, int number(int a);
Another statement we can have in a class definition is an implements clause.
We use this to implement interfaces. Interfaces contain only abstract methods
and interface constants.
Interface constants are constants declared with the final and static
keywords.
Abstract methods in the interface definition include the keyword abstract.
An interface is used via the implements clause in the class header. Two different classes
that implement the same interface can be used as parameters to the same
method as long as the parameter type in the formal parameter list is
the name of the interface.
Let's consider the examples in the blue book.