Computer Science 225
Advanced Programming
Spring 2021, Siena College
Lecture 4: More Interfaces; Anonymous Classes; Introduction to Inheritance (online synchronous)
Date: Friday, March 5, 2021
Agenda
- Announcements
- we're online synchronous today
- Monday will be online asynchronous - details coming
- Problem Set 1 graded, open Issues if you had something to be
considered for partial credit that hasn't been taken into account
- Lab 1: Java and Data Structures Refresher (in Canvas and GitHub) will be
graded soon
- Lab 2: Java Interfaces (in Canvas and GitHub) due 24 hours before your next lab
- Problem Set 2 will be out soon
- Java Interfaces
- casts and instanceof
- anonymous classes
- In-class exercises (5 assignment points), answer in a Google
document in your CSIS225 folder
- Write the Java statement that would implement sorting of our
array of Animal objects in the ZooArray example, this
time by number of legs from largest to smallest, using a
Comparator defined as an anonymous class passed directly as
a parameter to the Arrays.sort method.
- What changes would need to be made to the Dog class to
implement the Comparable interface, defining the ordering
based on a new int-valued field age?
- Overloaded methods
- Inheritance
- terminology
- a simple example
- protected and default protection
Terminology
- instanceof operator
- cast
- anonymous class
- inheritance
- overloading
- ad hoc polymorphism
- subclass/extended class
- superclass/base class
- extends
- derived class
- IS-A association
Examples