| | |
interfaces in java
![]() |
•
•
Join Date: Aug 2005
Posts: 216
Reputation:
Solved Threads: 8
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:
Implementing class:
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:
Java Syntax (Toggle Plain Text)
public interface Print1 { public void print1(); }
Implementing class:
Java Syntax (Toggle Plain Text)
public class ExampleClass implements Print1 { public void print1() { System.out.println("print 1"); } }
•
•
Join Date: Mar 2006
Posts: 2
Reputation:
Solved Threads: 0
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 .............
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 .............
•
•
•
•
Originally Posted by hooknc
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:
Java Syntax (Toggle Plain Text)
public interface Print1 { public void print1(); }
Implementing class:
Java Syntax (Toggle Plain Text)
public class ExampleClass implements Print1 { public void print1() { System.out.println("print 1"); } }
•
•
Join Date: Aug 2005
Posts: 216
Reputation:
Solved Threads: 8
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.
Then its easy to call the static method on B.
Java Syntax (Toggle Plain Text)
public interface A { public B getB(); } public interface B { public static String exampleStaticMethod(); }
Then its easy to call the static method on B.
Java Syntax (Toggle Plain Text)
public static void main(String[] args) { A a = new ImplementationOfA(); a.getB().exampleStaticMethod(); }
•
•
Join Date: Aug 2005
Posts: 216
Reputation:
Solved Threads: 8
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.)
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.)
•
•
Join Date: Aug 2005
Posts: 216
Reputation:
Solved Threads: 8
•
•
•
•
Originally Posted by hooknc
Finally, an Interface can only have one parent that it extends.
Defining an Interface
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
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.
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.
![]() |
Similar Threads
- Differences Between Java and C/C++ (C++)
- Composition (Java)
Other Threads in the Java Forum
- Previous Thread: help with JDBC oracle9i
- Next Thread: Any Java Source for 16 Questions
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game gameprogramming givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working






