1 of 14

To do: October 20

On the white board:

1. What is a similarity between an abstract class and an interface?

2. What is difference between an abstract class and an interface?

Tomorrow, I will not be in class. Mr. Newland will be administering a CS survey instrument during class. Will count as participation grade.

2 of 14

Another example of an interface: List

3 of 14

List interface

List list1 = new List();

error: List is abstract; cannot be instantiated

4 of 14

List interface

List list2 = new ArrayList();

list2 = new Stack();

list2 = new LinkedList();

5 of 14

List interface

List list2 = new ArrayList();

list2 = new Stack();

list2 = new LinkedList();

An ArrayList IS A List.

A Stack IS A List.

A LinkedList IS A List.

6 of 14

Go over homework

  • goformative: Abstract classes
  • goformative: Interfaces

7 of 14

Abstract classes

Abstract classes are declared abstract and an abstract class may include:

  • Instance variables (concrete)
  • Constructors (concrete)
  • Methods - modifiers/accessors (concrete)
    • Defined and implemented within the abstract class
  • Abstract methods
    • Header and purpose defined
    • Not implemented

8 of 14

Interface

  • Even more abstract
  • All elements are abstract, none are concrete
  • No instance variables
  • No implementations
  • Only names of methods and their basic purpose

9 of 14

What is an interface?

An interface is a list of methods that must be implemented.� �An interface may not contain any implemented methods.��Interfaces cannot have constructors!!!�

10 of 14

Type Parameters:�T - the type of objects that this object may be compared to

Compares this object with the specified object for order.

11 of 14

Interface Comparable <T>

int compareTo(T o)

currentObject.compareTo(parameterObject)

  • Returns 0 → objects are equal
  • Returns int<0 (negative integer) → current object precedes� parameter object
  • Returns int>0 (positive integer) → current object comes after� parameter object

12 of 14

Repl.it Polygon interface

13 of 14

Repl.it lab sort by vowels

14 of 14

Homework:

Replit labs: Polygon interface and sort by vowels