• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Interface

 
sarada devi
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I understand the question correctly, your instance of Call needs to have a reference to your instance of TestInter. For example...
 
amod gole
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

similarly
define an interface inside a class now implements that interface to another class
try these
 
Stuart Ash
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic