Interface - Intro

todays lesson

  • interfaces (before and after java 9)

    • interface, implements

  • instanceof

  • Comparable and compareTo

    • Arrays.sort()

    • Collections.sort()

interface (until java 7)

  • use keyword implements to implement the interface

  • need to implement all methods of the interface

  • you can't create an object of type interface (since its abstract)

  • a class can implement multiple interfaces or just a single interface

  • Interface methods are by default abstract and public

  • Interface attributes are by default public, static and final

  • An interface cannot contain a constructor (as it cannot be used to create objects)

What is the output?

another example

interfaces since java 9 more complicated 🙄

add the capabilities of the previous

  • access modifiers

    • before java 9: public but not private, protected

    • since java 9:

      1. static methods

      2. private methods

      3. private static methods private static void sub(int a, int b)

      4. default methods

      5. and a few more changes

example

Arraylist example

Last updated

Was this helpful?