public class thermostst{

private float currenttemp();


I thought in java only abstract classes can contain abstract methods like this!
I got this from a algorithms and data structures book and im guessing its a printing mistake and currenttemp should not contain the () .

Thank You

5 Years
Discussion Span
Last Post by JamesCherrill

No, it's not valid. The method currenttemp() must either have a body in {} or be declared abstract, in which case the class must also be declared abstract.
Without the () currenttemp becomes a float variable, not a method, and the code is valid.
We can only guess what the original author intended, but if he was following standard Java conventions that method would be called getCurrentTemp(), but then it wouldn't be private. My guess is that it's probably intended to be a variable.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.