• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

interfaces

 
Ranch Hand
Posts: 4702
9
Scala Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4702
9
Scala Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4702
9
Scala Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 318
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!