wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Java head: object references variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java head: object references variables" Watch "Java head: object references variables" New topic
Author

Java head: object references variables

Omar Perez
Ranch Hand

Joined: Jul 08, 2011
Posts: 36
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
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14269
    
  21

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 8 API documentation
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).
 
wood burning stoves
 
subject: Java head: object references variables