Object Oriented Programming in JAVA
CS 201
 

Definition of "Class"
  • A class is a blueprint or prototype that defines the variables and methods common to all objects of a certain kind.
     
  • Different objects can have the same class
    -- Cars, Vans, Trucks are all objects of the class automobile


        
     
  • Structure of Class Definition
     

     

  • A simple class, called "Time" (Partial)
     
    class Time
    {
      private int hour, minute;

      public Time (int h, int m)
      {
        hour = h;
        minute = m;
      }

      public void addMinutes (int m)
      {
     
       int totalMinutes = ((60*hour) + minute + m) % (24*60);

     
       if (totalMinutes<0)

        totalMinutes = totalMinutes + (24*60);
        hour = totalMinutes / 60;
        minute = totalMinutes % 60;
      }
    }

Prev | Home | Next


Mihir Patel | CS561
Illinois Institute of Technology