Results 1 to 3 of 3
  1. #1
    überfuzz is offline Member
    Join Date
    Feb 2011
    Posts
    43
    Rep Power
    0

    Default Call object - syntax

    Hi all!

    I'm only just started with java. When I thinker with some simple classes/objects I don't know how to call/use objects in my code. Let me clarify with an example.

    Example:
    File: Car.java
    Java Code:
    public class Car(){ heaps of code...}
    File: Race.java
    Java Code:
    public class Race()
    {
      //How do I call Car in the constructor?
      //How do I call Car in a method? Let's say I want to create an array of the type Car. 
      Car[] arrayOfCars = new Car[random];
      //etc...
    }
    Sorry if I ask stuff like this. I just need to get started on this, bear with me.


    Edit
    When I do this:
    PHP Code:
    Object [] array_containing_objects = new Object[10];
    I get this message for DrJava;
    Java Code:
    Static Error: Undefined name 'array_containing_objects'
    Last edited by überfuzz; 02-06-2011 at 09:10 PM. Reason: Added info

  2. #2
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    how to create java classes and constructors look here. if you have questions about the tutorial let me know.

  3. #3
    überfuzz is offline Member
    Join Date
    Feb 2011
    Posts
    43
    Rep Power
    0

    Default

    Thanks!

    Argh, it seems I missed out on what I did wrong... I can create an Object from an external file. This works:
    Java Code:
    ExternalObject TestObject = new TestObject();
    I guess I do something wrong when I try to create an array with the type of ExternalObject in my code.

    How should I do if I like to have an array containing objects..?

    Edit, I found the syntax of how create and work with an array of objects.
    Last edited by überfuzz; 02-06-2011 at 11:06 PM.

Similar Threads

  1. How to call an object from another class?
    By narty in forum New To Java
    Replies: 1
    Last Post: 11-01-2010, 08:14 PM
  2. call by value and call by reference in java
    By sandeepsai39 in forum New To Java
    Replies: 7
    Last Post: 08-12-2010, 11:03 AM
  3. How to create object dinamically and call methods.
    By Gelembjuk in forum New To Java
    Replies: 8
    Last Post: 10-26-2008, 09:28 AM
  4. Replies: 0
    Last Post: 01-28-2008, 07:02 AM
  5. syntax error
    By gabriel in forum New To Java
    Replies: 3
    Last Post: 08-03-2007, 03:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •