Monday, 10 June 2013

Interfaces

So talking about interfaces it is just nothing but like classes it is defined with the symtax as follows

interface name of interface{
body
}
Talking about the body--
only  data types  declared as final can be used or declared in it other ones will not work and just believe me because i have tried it and so can you heres a example how it works
1-- simple program to find area of circle
 interface rocks{
final double pi=3.14;

}
class circle implements rocks
{
double a=0;
void shocks(int x)
{
a=pi*x*x;
System.out.println("area of circle is"+a);
}
}
class testing{
public static void main(String arg[])
{
circle object=new circle();
object.shocks(5);
}
}
like in classes we have to write extend keyword to inherit from other class
likeways here we write implements as you can see
So this was how you use data types in next one i'll show you how to use functions

No comments:

Post a Comment