wood burning stoves
The moose likes Java in General and the fly likes Java  Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java  Interface" Watch "Java  Interface" New topic

Java Interface

sarada devi

Joined: Jan 04, 2006
Posts: 7

I have written one interface testInter.java i declare setName() method in testInter.java, and i have written class test.java. I Implemented testInter.java in test.java.
I have written another class call.java.
Can i call method of Interface testInter.java in call.java??

Thank You,
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Well I'm not sure what you what you mean about calling a method of an interface. The interface has no implementation for it's methods. You can include a method with the same name as the one in your interface in call.java as long as you don't have a method already with that signature.
marc weber

Joined: Aug 31, 2004
Posts: 11343

If I understand the question correctly, your instance of Call needs to have a reference to your instance of TestInter. For example...

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
amod gole
Ranch Hand

Joined: Dec 07, 2005
Posts: 83
hi sarada devi,

first that you are created one interface testInter.java

you are implementing that interface to your class test.java
that means you are overridding that method in your class

now you want to use that method in other class call.java

this is your q?

you can call that method only with the help of object of class test.java
this is basic after practcing you can get an idea that how to call method from one class to another class
amod gole
Ranch Hand

Joined: Dec 07, 2005
Posts: 83
thanks marc weber ,
you explain all the things with example,

sarada devi ,

to get an complete grip on interface try out these

defined a class inside interface try to access method of that class in another class where you are not implementin that interface

define an interface inside a class now implements that interface to another class
try these
Stuart Ash
Ranch Hand

Joined: Oct 07, 2005
Posts: 637
It might be useful to read up some good material on how interfaces matter and what their real use is - both from designer and developer perspectives.

I recommend Thinking in Java.

ASCII silly question, Get a silly ANSI.
I agree. Here's the link: http://aspose.com/file-tools
subject: Java Interface
It's not a secret anymore!