Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Error in calling setter method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error in calling setter method" Watch "Error in calling setter method" New topic
Author

Error in calling setter method

Achint Verma
Greenhorn

Joined: Jul 13, 2012
Posts: 12
I get these errors on Eclipse upon calling the setter method setSize().
Is there anything wrong in line 4 ?

Multiple markers at this line
- Syntax error on token(s), misplaced
construct(s)
- Syntax error on token "34", delete this
token


for the code



Can anyone explain why am I getting these errors ?
Raghu Devatha
Ranch Hand

Joined: Feb 10, 2009
Posts: 39
The line b.setSize(34); should be in a method of Class A because the method setSize does not return anything.


dR
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38107
    
  22
Right answer, wrong explanation; the reason is that statements cannot be put loose in the class. You ought to put those statements into a method. It is only the 3rd line the compiler will complain about because the 1st and 2nd lines are declarations, which are permitted loose in the class
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7554
    
  18

And welcome to JavaRanch Achint.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
Don't get me started about those stupid light bulbs.
 
subject: Error in calling setter method
 
Similar Threads
problem in System.out.println
Thread-safe
java problem
Confusion regarding object creation in Java.
Encapsulation - data hiding issue