classes

interface Scanner {
    String scan();
}

class NmapScanner implements Scanner {
    public String scan() {
        return "nmap ready";
    }
}

Java has interfaces, not multiple inheritance of classes That decision is why the language is simpler to reason about in large systems

Access

ModifierClassPackageSubclassWorld
publicyesyesyesyes
protectedyesyesyesno
packageyesyesnono
privateyesnonono

Package private is the default It is the most useful access level and the least used by beginners

Inheritance

class Media {
    String name;
    Media(String name) { this.name = name; }
}

class Song extends Media {
    String artist;
    Song(String name, String artist) {
        super(name);
        this.artist = artist;
    }
}

super(...) calls the parent constructor first Call it before using this in the child

Overriding

@Override
public String toString() { return name; }

@Override is optional for compilation It is not optional for review It catches a method that does not actually override anything

Next

Collections in 05 collections

Posted