Java Syntax - class

Discussion in 'Java' started by Jenny, Sep 1, 2004.

  1. Jenny

    Jenny Guest

    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();
    }
    }
     
    Jenny, Sep 1, 2004
    #1
    1. Advertising

  2. (Jenny) writes:

    > 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").
     
    Tor Iver Wilhelmsen [TeamB], Sep 1, 2004
    #2
    1. Advertising

  3. Jenny wrote:

    >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

    --
    Thomas<dot>Fritsch<squiggle>ops<dot>de
     
    Thomas Fritsch, Sep 1, 2004
    #3
  4. Jenny

    Oscar kind Guest

    Jenny <> wrote:
    > 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.


    --
    Oscar Kind http://home.hccnet.nl/okind/
    Software Developer for contact information, see website

    PGP Key fingerprint: 91F3 6C72 F465 5E98 C246 61D9 2C32 8E24 097B B4E2
     
    Oscar kind, Sep 1, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. E11
    Replies:
    1
    Views:
    4,788
    Thomas Weidenfeller
    Oct 12, 2005
  2. gabriele renzi
    Replies:
    2
    Views:
    205
    gabriele renzi
    Dec 31, 2005
  3. Ken Bloom
    Replies:
    3
    Views:
    213
  4. Good Night Moon
    Replies:
    9
    Views:
    284
    Rick DeNatale
    Jul 25, 2007
  5. Jacob Grover
    Replies:
    5
    Views:
    318
    Jacob Grover
    Jul 18, 2008
Loading...

Share This Page