This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "interfaces" Watch "interfaces" New topic
Author

interfaces

Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4095
    
    1
Im confused. AudioClip is an interface. All methods of interfaces are abstract right? If so then why does this code play the .au files?

[I added UBB CODE tags to your source code to make it more readable. Please try to use
them in the future. Learn more about UBB codes here - Ajith ]
[This message has been edited by Ajith Kallambella (edited November 10, 2000).]


SCJP
Rajesh Hegde
Ranch Hand

Joined: Sep 15, 2000
Posts: 112
Hi Randall,
I'll give u a hint and you try to figure out what could be the answer okay.
" a reference variable of interface type can contain the reference to an object implementing the interface."
If u got that , then let me know.
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4095
    
    1
thanks to both of you i will read about the formatting thing in a minute. Here is from the API
getAudioClip
public AudioClip getAudioClip(URL url,
String name)
Returns the AudioClip object specified by the URL and name arguments.
This method always returns immediately, whether or not the audio clip exists. When this applet attempts to play the audio clip, the data will be loaded.
Parameters:
url - an absolute URL giving the base location of the audio clip.
name - the location of the audio clip, relative to the url argument.
Returns:
the audio clip at the specified URL.
See Also:
AudioClip
however if you click on the links for AudioClip it takes you to the AudioClip interface so I was confused. It is still somewhat confusing since an AudioClip object doesnt belong to a class AudioClip(since there is no such class). How is an AudioClip object made if there is no constructor defined for it?
Rajesh Hegde
Ranch Hand

Joined: Sep 15, 2000
Posts: 112
Hi Randall,
Its this way:
AudioClip is an Interface no doubt.
Inside the getAudioClip API , an object of a class that implements the AudioClip interface is create. The refernce to this object is then returned by the API.
class X implements AudioClip
{
}
AudioClip getAudioClip()
{
AudioClip var;
var=new X();
return var;
}
Hope that helps .
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4095
    
    1
Once while visiting sun's site(some time ago) I stumbled upon a different style of "javadoc" which actually showed the source code of the methods of whatever class you were looking at. I think it was for an older version of java. Is there a similar document for 1.3? Does anyone know the url to it and if it is downloadable?
Matt DeLacey
Ranch Hand

Joined: Oct 12, 2000
Posts: 318
Hey,
This used to confuse me too (and I'm still definately not at 100% with abstract classes), but I finally came to the realization that although you can't call the constructor of an abstract class, you can instatiate them...you just can't initialize them. Also, abstract classes can have methods that are defined (although maybe interfaces cannot). Could that perhaps be the answer? Could there be static functions defined in the interface?
Matt
mohit joshi
Ranch Hand

Joined: Sep 23, 2000
Posts: 243
static functions cannot be defined in an interface, it would result in compile time error.
The reason is that abstract methods cannot be static and all methods of interface are implicitly abstract.
One possible reason why abstract methods cannot be static may be that abstract methods are meant to be overridden to provide implementation, and static methods cannot be overridden, but are hidden.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: interfaces
 
Similar Threads
critique my applet?
problem with refactored program
painting from user defined class
Help with displaying data in JTextfield
objects of an interface type