Esempio: la Classe Student



In generale una classe ha sia il ruolo di prototipo per gli oggetti che il ruolo di contenitore di variabili e metodi statici.

public class Student {

   public String name;  // Student's name
                        // variabile d'istanza
   public int ID;    // unique ID number
   public double test1, test2, test3;
                    // grades on three tests

   public double getAverage() {
                    //compute average test grade
                    // metodo d'istanza
       return (test1 + test2 + test3) / 3;
       }

   private static int nextUniqueID = 1;
\                    // variabile statica

   public static int getUniqueID() {
                    // return a unique ID
                    // metodo statico
       int thisID = nextUniqueID;
       nextUniqueID++;
       return thisID;
       }
    }  // end of class Student


arrow1_left.gif (1097 byte)arrow1_right.gif (1095 byte)