• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java head: object references variables

 
Omar Perez
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15441
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ove Lindström
Ranch Hand
Posts: 326
Android Firefox Browser Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic