CIS 121 February 11, 2000


Individual account have been established for this lab. Your account name is the letter c followed by your student number. Your initial password is computer. Once you have logged on, you must change your password. To do this, hit CTRL+ALT+DEL. Click Change Password. This account is only valid in this room. If you are taking courses that meet in FCE 19 or FCW 23, your accounts in those rooms are independent of your account in this room.

In order to gain entry to the lab between 6:00 am and 11:00 pm, you may use your Student ID. After you slide your card face down through the reader, enter a 0 followed by the last three digits of your Social Security number on the touch pad. If you enter it correctly and you have access to the room, you will hear a click. You may then push the door open. The handle on the door will not turn. After you enter the room, please close the door behind you. Do not allow anyone who should not be in the lab to enter. Names of people who have entered the lab using their card are logged, and if any equipment is missing, those individuals will have to answer to the authorities. No one should need for you to let them into the room, so please do not answer the door if someone knocks. If you have problems using your card to enter the lab, let me know. Please be responsible when using the printer because paper and toner are very expensive.

Recall the Room3D.java example. There are a couple of points that should be elaborated upon.

  • In the constructor for Room3D, we used the statement

    super(width,length);


    This is a call to the constructor of the super class of Room3D, Room. It must be the first line of the constructor. If we do not explicitly call the constructor from the super class, then the default constructor of the super class is used. If the super class has no default constructor, and we do not make a call to a constructor in the super class, we will get an error.

    In any class that implements another class, we can access variables and methods by using the keyword super.

  • We implement an equals methods. The equals method was inherited from the super class Object since we are using the signature of the method defined in Ojbect.java. The formal parameter to this method is of type Object. This really gives us no information because every object is of type Object. In order to use this parameter, we must cast it to the type of object we need.

    The dot operator has a higher precedence than the cast operator. That is, if we used the code

    (Room3D)other.width


    then the interpreter would first perform the dot operator and then try to cast that as a Room3D object.

    What we want is to cast the parameter other as a Room3D object, and then access its instance variable width, so we use parantheses so that the cast is performed first.

    ((Room3D)other).width


  • Note that in this example, we chose to use the same signature as the method equals as defined in Object.java. If we change the formal parameter list on a method, this is called method overloading. If we change the implementation, this is called method overriding.

  • We need to clarify the use of method overriding. As stated in class, we can change the implementation of a method we inherit, then we can't change its signature. However, if we change the formal parameter list, we can overload the method. If we do not change the formal parameter list, then we cannot change the return type or access control keyword. If we change the parameter list, then the method is considered a different method, and we can change the signature.

  • In Java, we may only extend one class. This is called single inheritance.

  • There are two interfaces we want to consider. They are the Cloneable interface and the Serialiazable interface. These are called tag interfaces because they don't have any methods associated with them. They are simply flags that tell the given class it has certain properties.

  • The Cloneable interface allows us to make a clone of an object.

  • The Serializable interface allows us to write to and read from and ObjectOutputFile. This is accomplished through the methods writeObject() and readObject().

  • If a data member of an object is defined with the keyword transient, then when the object is serialized (written to a file), that data member is not written.

  • When we use the readObject() method, we must know what type of object we are reading in, so that we can cast it to the appropriate type.

  • Let us consider the examples of the Cloneable and Serializable interfaces in the blue book.