Java Syntax - class

J

Jenny

Hi,

In the code below, what is class in
Applet.newAudioClip(Test1.class.getResource("ladieu.wav")).play()? I
could not such property in Object class. Thanks.

import java.applet.*;
public class Test1 {
public static void main(String args[]) {
Applet.newAudioClip(Test1.class.getResource("ladieu.wav")).play();
}
}
 
T

Tor Iver Wilhelmsen [TeamB]

Applet.newAudioClip(Test1.class.getResource("ladieu.wav")).play()? I
could not such property in Object class. Thanks.

It's syntactic sugar for the compiler - not a "real" variable. In
effect, it does the same as Class.forName("Test1").
 
T

Thomas Fritsch

Jenny said:
Hi,

In the code below, what is class in
Applet.newAudioClip(Test1.class.getResource("ladieu.wav")).play()? I
could not such property in Object class. Thanks.

import java.applet.*;
public class Test1 {
public static void main(String args[]) {
Applet.newAudioClip(Test1.class.getResource("ladieu.wav")).play();
}
}
It is the so-called class literal.
Loosely speaking you can think of it as a static variable implicitly
declared like
public final static Class class = ...;
in every Java class.
For the exact definition see
http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#251530
 
O

Oscar kind

Jenny said:
In the code below, what is class in
Applet.newAudioClip(Test1.class.getResource("ladieu.wav")).play()? I
could not such property in Object class. Thanks.

Test1.class is a read-only property that refers to the Class object
representing the Test1 class.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top