Results 1 to 3 of 3
Thread: Call object - syntax
- 02-06-2011, 09:58 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 43
- Rep Power
- 0
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...}
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... }
Edit
When I do this:
PHP Code:Object [] array_containing_objects = new Object[10];
Java Code:Static Error: Undefined name 'array_containing_objects'
Last edited by überfuzz; 02-06-2011 at 10:10 PM. Reason: Added info
- 02-06-2011, 10:51 PM #2
how to create java classes and constructors look here. if you have questions about the tutorial let me know.
- 02-06-2011, 11:35 PM #3
Member
- Join Date
- Feb 2011
- Posts
- 43
- Rep Power
- 0
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();
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-07-2011 at 12:06 AM.
Similar Threads
-
How to call an object from another class?
By narty in forum New To JavaReplies: 1Last Post: 11-01-2010, 09:14 PM -
call by value and call by reference in java
By sandeepsai39 in forum New To JavaReplies: 7Last Post: 08-12-2010, 12:03 PM -
How to create object dinamically and call methods.
By Gelembjuk in forum New To JavaReplies: 8Last Post: 10-26-2008, 10:28 AM -
If JNI thread call the java object in another thread, it will crash.
By skaterxu in forum Advanced JavaReplies: 0Last Post: 01-28-2008, 08:02 AM -
syntax error
By gabriel in forum New To JavaReplies: 3Last Post: 08-03-2007, 04:26 PM
Bookmarks