Program 6.5: A Web Site Class with no public fields

Program 6.5 is a website class that makes the fields non-public. They can then be set with the three set methods as demonstrated in Program 6.6.

public class website {

  String name;
  String url;
  String description;
  
     public void setName(String s) {
     name = s;
  }

     public void setURL(String s) {
     url = s;
  }

     public void setDescription(String s) {
     description = s;
  }
  public void print() {
    System.out.println(name + " at " + url + " is " +
      description);
  }

}

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