File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java head: object references variables" Watch "Java head: object references variables" New topic

Java head: object references variables

Omar Perez
Ranch Hand

Joined: Jul 08, 2011
Posts: 36

I'm getting this error C:\Users\Omar\Desktop>javac '(' 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: 14338

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).
jQuery in Action, 2nd edition
subject: Java head: object references variables