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 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
abstract
andpublic
Interface attributes are by default
public
,static
andfinal
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 notprivate
,protected
since 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