aspose file tools
The moose likes Beginning Java and the fly likes Java head: object references variables Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 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
    
    3

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).
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Java head: object references variables
 
Similar Threads
NoClassDefFoundError - What did I do wrong?
'void' type not allowed here
really basic question, arrays .util package
can someone explain to me why the output would say null?
Learning about objects