(Lec-24)Java SE(Interfaces)
(Lec-24)Java SE(Interfaces)
(CORE JAVA)
LECTURE -24
Today’s Agenda
• Interfaces in Java
Syntax:-
interface <interface name>
{
<data type> <variable>= value;
<return type> <method name>(argument);
--------
--------
--------
}
class A implements <interface name>
{
-------
-------
}
Using interface as
Global Constants
import java.util.*; return kg*KG_TO_G;
interface Conversions }
{ public double
double KG_TO_G=1000; inch_to_mm(double inches)
double INCH_TO_MM=25.4; {
double kg_to_grams(double kg); return
double inches_to_mm(double inches*INCHES_TO_MM;
inches); }
} }
class TryConversions
implements Conversions
{
public double kg_to_gm(double
kg)
{
Using interface as
Global Constants
class UseShape
{
public static void main(String [ ] args)
{
Shape s;
s=new Rectangle(10,20);
S.o.p(“Shape is ”+s.getName());
S.o.p(“Its area is ”+s.area());
s=new Triangle(5,10);
S.o.p(“Shape is ”+s.getName());
S.o.p(“Its area is ”+s.area());
}
}
Inheriting one interface
into another
• Just like we inherit a class into another similarly, we
can inherit an interface into another.