• Post Reply Bookmark Topic Watch Topic
  • New Topic

very basic question on Classes  RSS feed

 
ed jones
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get a syntax error in the following

the error is at Ball ball

I'm trying to understand why I get this error?

thanks
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ed,

Actually "Ball ball;" is OK -- it's the next line that's the problem. A class body can't contain statements, only variable declarations. That means that a line like this is legal in your class body:

Ball ball = new Ball(100,100);

but (seemingly) doing the exact same thing in two separate lines is not!

The line

ball = new Ball(100,100);

by itself, which doesn't declare a variable, but rather just assigns a value to one, is not legal outside of a method. So you could put that line into Ball's constructor, or some other method -- just not where you have it right now.
 
ed jones
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the speedy reply
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!