Monday, 10 June 2013

Interfaces

So in this one well be using functions
what we do is just define them in the interface and then their body is specified in the class
you might be thinking if we have to specify body in the class then why not function also
well i dont know why right now but as it is a feature so we just have to get use to it  and it might be used
further in java so just bear with me
here's a simple example to show what i am saying
1--
interface a{
public void rec();
}
class b implements a
{
int n=12345;
int reverse=0;
public void rec(){

while(n>0)
{
reverse = reverse * 10;
reverse = reverse + n%10;
n = n/10;
}
System.out.println(""+reverse);

}
}
class dd{

public static void main(String arg[]){

b object = new b();

object.rec();
}
}

No comments:

Post a Comment