OOPJ - Unit 5
OOPJ - Unit 5
OOPJ - Unit 5
All Classes
& Interfaces
But not sub
packages
2. import package.classname;
3. import fully qualified name
Name Conflicts
Sub Package
Static import
• to access any static member of a class directly.
There is no need to qualify it by the class
name.
Interface
• Interfaces specify what a class must do and not how. It
is the blueprint of the class.
• An Interface is about capabilities like a Player may be
an interface and any class implementing Player must
be able to (or must implement) move(). So it specifies a
set of methods that the class has to implement.
• If a class implements an interface and does not provide
method bodies for all functions specified in the
interface, then class must be declared abstract.
• A Java library example is, Comparator Interface. If a
class implements this interface, then it can be used to
sort a collection.
• Abstraction, Multiple Inheritance, IS-A relationship.
Java 8 Interface (Improvement)
Example
• It is both permissible and common for classes
that implement interfaces to define additional
members of their own.
Accessing Implementations Through
Interface References