Week3_Forms of inheritance (1)
Week3_Forms of inheritance (1)
Interface,
Implementation
Week 3
Objectives:
• Explain the function of
interface class in java
• Understand the use of
interface class in java
• Demonstrate how interface
class works.
Interfaces in Java
• An Interface in Java programming
language is defined as an abstract
type used to specify the behavior
of a class.
• An interface in Java is a blueprint
of a class.
• A Java interface contains static
constants and abstract methods.
Interfaces in Java
• Like a class, an interface can have
methods and variables, but the methods
declared in an interface are by default
abstract (only method signature, no body).
• 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
the class must be declared abstract.
How to Create a interface class…………
Why do we use an Interface?
Output
Interface Class
Main Class
Example of Interface
Demo Code………
https://www.geeksforgeeks.org/c-sharp-inheritance-in-interfaces/