Java Practical 3
Java Practical 3
Practical No. 03
Aim:
Develop an interface to calculate and print the area of different 2D
Shapes. Give name of the interface as “Area”. Create a menu driven
program to provide the user menu to choose and calculate Area of
different 2D shapes such as circle, triangle and rectangle etc.
THEORY:
Interface:
An interface in Java is a blueprint of a class. The interface in Java is a mechanism to
achieve abstraction. There can be only abstract methods in the Java interface, not method body.
It is used to achieve abstraction and multiple inheritance in Java. It cannot have a method body.
Java Interface also represents the IS-A relationship.
There are mainly three reasons to use interface. They are given below.
An interface is declared by using the interface keyword. It provides total abstraction; means all
the methods in an interface are declared with the empty body, and all the fields are public, static
and final by default. A class that implements an interface must implement all the methods
declared in the interface.
Start
Stop
OUTPUT:
DISCUSSION QUESTIONS:
1) Give the difference between a Method and an Interface.
REFERENCE: