4 Replies Latest reply: Mar 15, 2013 11:06 PM by 997078 RSS

    About Class Object  as Array

    997078
      Hello.. I'm beginner in Java Programming

      Now i learn about Array.. i'm not understand about use class object become array. for example i'm create class object Card.
      Then i call Card object to CardTest as main object and Card object called as array.

      can you tell me about how to work Card object as array in CardTest ?

      Edited by: 994075 on Mar 14, 2013 11:55 PM
        • 1. Re: About Class Object  as Array
          gimbal2
          I believe you are asking about creating an array of Card objects here, but it is not very clear.
          Card[] cards = new Card[10];
          cards[0] = new Card(bla);
          cards[1] = new Card(bla);
          etc.
          or
          Card[] cards = new Card[10];
          
          for(int i = 0; i < cards.length; i++){
            cards[i] = new Card(bla);
          }
          • 2. Re: About Class Object  as Array
            997078
            yup..thanks guru :D

            so i guess Object Class can be array :).
            but i'm not understrand if static method in Card object can be called automatically when Card initialized in CardTest?
            • 3. Re: About Class Object  as Array
              gimbal2
              994075 wrote:
              yup..thanks guru :D
              I'm no guru, I just bought a decent Java book 10 years ago and here I am.
              so i guess Object Class can be array :).
              I don't get that statement. You can store objects in an array, if that's what you mean. An array itself is also an object.
              but i'm not understrand if static method in Card object can be called automatically when Card initialized in CardTest?
              a) research constructors
              b) you usually don't need static methods, its just something that people new to the language tend to overuse because then you don't have to create object instances. Forget about static methods, try to make it work using regular non-static methods.

              And you really should read and study more, you're coming to the forum way too soon. First get a solid knowledge base, the only thing you're doing now is asking questions that you could have answered for yourself by studying more.
              • 4. Re: About Class Object  as Array
                997078
                ok..thanks a lot, gimbal2 :)