hey! i m reading java. and at one place i have read Audio interface in which play(), loop() functions are defined,but interface is something in which there can't be any method defined. so this must be abstract not interface.so please tell this problem, y we are calling this as interface. AudioClip interface, i am talking about!! i m have read it's API also, but here also it is defined as interface but at there only, play() like methods are defined in it. how is it possible?
gourav1 -12 Posting Whiz in Training
Recommended Answers
Jump to Posttake a look at this
in an interface, you can declare methods, you just don't give them a 'body'.
which means:
public void play();
is allowed
Jump to Postalso, you're not necessarily 'calling' the interface.
for instance:public interface IntA{ public void run(); } public class ClaB{ public ClaB(){ } public void run(){ } }
if you have something like this, you can, for example, code:
public static void main(String[] args){ IntA …
Jump to Postyou don't 'inherit' an interface, you implement it.
inheriting means you don't have to write the code, there's a complete functional method, including body and logic in the class you're inheriting. you only need to write the method yourself if you would like to adjust the logic therein.
implementing an …
Jump to Postah, yes off course, that was a mistake by my part :D
indeed, your ClaB needs to pass a Is-A test for IntA, so it needs to either inherit, or in this case, since it's an interface, implement it :)so, indeed, it should be:
public …
Jump to PostAFAIK that shouldn't even compile.
you can't instantiate the interface itself, unless you assign it to be one of the classes which implement it.
could you paste your code here, so we can have a look at it?
All 21 Replies
thines01 401 Postaholic Team Colleague Featured Poster
gourav1 -12 Posting Whiz in Training
stultuske 1,116 Posting Maven Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
stultuske 1,116 Posting Maven Featured Poster
gourav1 -12 Posting Whiz in Training
stultuske 1,116 Posting Maven Featured Poster
gourav1 -12 Posting Whiz in Training
stultuske 1,116 Posting Maven Featured Poster
gourav1 -12 Posting Whiz in Training
stultuske 1,116 Posting Maven Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
gourav1 -12 Posting Whiz in Training
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
stultuske 1,116 Posting Maven Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
thines01 401 Postaholic Team Colleague Featured Poster
stultuske 1,116 Posting Maven Featured Poster
thines01 401 Postaholic Team Colleague Featured Poster
stultuske 1,116 Posting Maven Featured Poster
thines01 401 Postaholic Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.