| Author |
Java head: object references variables
|
Omar Perez
Ranch Hand
Joined: Jul 08, 2011
Posts: 35
|
|
Greetings,
I'm getting this error C:\Users\Omar\Desktop>javac Dog.java
Dog.java:17: '(' or '[' expected
myDogs[2]=new dog1;
^
1 error
What I'm doing wrong?
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12929
|
|
|
Look at line 17. The syntax for creating a new Dog object is wrong there. Note that in line 15 and 16 you're doing it correctly. Why did you suddenly do it differently in line 17?
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Ove Lindström
Ranch Hand
Joined: Mar 10, 2008
Posts: 326
|
|
In other languages you may do a copy of an already existing object by using something like the syntax you have on line 17.
In this case, I think that you wanted to put the dog1 into the last position of the array and you should just assign it (remove the new keyword).
|
 |
 |
|
|
subject: Java head: object references variables
|
|
|