Inheritance and Objects Continued

Inheritance and Objects Continued

Object Casting

  • Fine:
 Undergraduate U = new Undergraduate();
    Student S = U; // because an Undergraduate is always a student
  • Error:
 Student S = new Undergraduate(); // fine
    Undergraduate U = S; // error
    Undergraduate U = (Undergraduate) S;  // fine, ``Object Casting"
    
    // ``Type-check"
    if (s instanceof Undergraduate) {
        U = (Undergraduate) S;
    } 

Calling Super in a constructor

  • When you make an object, a constructor for its superclass is also called.
  • You specify which constructor you want with the ``super" notation:
 public Student(string initialName; int initialNumber) {
        super(initialName);
        studentNumber = initialNumber;
    }

Class Object

  • In Java, the class ``Object" is the descendant of ALL classes
  • Object Methods (that are important)
    • toString > returns a printable thing of the object
    • hashCode > returns an int used for the hash collections
    • clone > makes copies

Abstract Classes

  • An abstract class has one or more methods that are undefined, and must be defined by a subclass.
  • Allows the creation of a base object that does not implement any functionality:
 public abstract class Figure
    {
        ...
        public abstract void drawHere();
        ...
    }

Polymorphism

manyforms

Three Main Features of OOP

blarg, see the PPT for more!

UML (Unified Modeling Language)

  • ``A general-purpose visual modeling language that is used to specify, visualize, construct, and document the artifiacts of a software system"

Uses 9 types of diagrams

  • Class Diagrams - Classes and associations
  • Inheritance Diagrams - show class relationships
  • Object diagrams - represent specific objects

Usually, only required details are included. Not every method and instance variable

Java GUI Development

JFrame

lotsa cool stuffs.