Hey can any body help in this matter:


interface with in interface :

ex: interface ee
{
interface rr{
void ere();
}
}

how to implement the ere method :

please sugesst me

Regards

Saranga

An interface doesn't actually implement any behavior. It only defines behavior.

So if you define a method called print1() the code for printing out a 1 would not actually be in the interface class. The behavior would have to be defined by a class that implements the interface.

Interface:

public interface Print1
{
  public void print1();
}

Implementing class:

public class ExampleClass implements Print1
{
  public void print1()
  {
    System.out.println("print 1");
  }
}

Thanks for u suggestion,

But i would lilke to know , if there exist an interface , with in that an interface there exist an another interface ..... in that an method is there .if that inner interface is an static than how u will implement . that method .............

An interface doesn't actually implement any behavior. It only defines behavior.

So if you define a method called print1() the code for printing out a 1 would not actually be in the interface class. The behavior would have to be defined by a class that implements the interface.

Interface:

public interface Print1
{
  public void print1();
}

Implementing class:

public class ExampleClass implements Print1
{
  public void print1()
  {
    System.out.println("print 1");
  }
}

Since an Interface has no behavior it cannot be a container and therefore it cannot contain another interface. Now, a Interface can define behavior that says its Implementing class can return a different Interface.

public interface A
{
  public B getB();
}


public interface B
{
  public static String exampleStaticMethod();
}

Then its easy to call the static method on B.

public static void main(String[] args)
{
  A a = new ImplementationOfA();
  a.getB().exampleStaticMethod();
}

Well, you can extend (is a) yes, but an Interface cannot contain (has a) another Interface.

I feel as thought containing another Object is behavior and Interfaces don't have any behavior of their own. The do define behavior, but they don't implement any behavior.

Finally, an Interface can only have one parent that it extends.

(I'm positive you know all this s_c, just hoping to clarifying for all the kiddies.)

It's confusing stuff. What I think is weird is how an interface can extend as many interfaces as it wants, but a regular class can only extend one..

Finally, an Interface can only have one parent that it extends.

I stand corrected. server_crash is correct. An interface and Extend any number of interfaces. This is quite a shock to me.

Defining an Interface

I didn't meant to correct you... Actually I didn't even know you posted that ;)

That's just one of the things I find really weird about interfaces and it took me a while to grasp it. I always thought it was, 'you extend classes with special functionality', but 'implement interfaces'. I guess it's just different when you're talking about interfaces. Oh well, I don't use them very often.

This article has been dead for over six months. Start a new discussion instead.