Program 7.11: The returnDelimitedWebsite Class with an additional method

As a practical example suppose the webmaster wants a quick way to test if the length of the description field in a returnDelimitedWebsite is greater than 256 characters. You can add a boolean method called over256 to the returnDelimitedWebsite class like this.

public class returnDelimitedWebsite extends website {

  public returnDelimitedWebsite(String n, String u, String d) {

      super(n, u , d); 

    }

    public String toString() {
  
    return getName() + '\r' + getURL() + 
      '\r' + getDescription() + '\r';
  
  }

    public boolean over256() {
  
    if (getDescription().length() > 256) return true;
    return false;

  }

}
The over256 method is simple. It gets the description String using getDescription and then tests the length of that String with the length method from java.lang.String. If the length is greater than 256 the method returns true. Otherwise it returns false. Nothing at all like this is present in the website class and nothing needs to be.


Copyright 1996 Elliotte Rusty Harold
elharo@sunsite.unc.edu
This Chapter
Examples
Home