Interface - Intro
todays lesson
interfaces (before and after java 9)
interface,implements
instanceofComparable and
compareToArrays.sort()Collections.sort()
interface (until java 7)
use keyword
implementsto implement the interfaceneed 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
abstractandpublicInterface attributes are by default
public,staticandfinalAn 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:
publicbut notprivate,protectedsince java 9:
static methods
private methods
private static methods
private static void sub(int a, int b)default methods
and a few more changes
example
Arraylist example
Last updated
Was this helpful?