Skip to main content

Can't create a class method

2 replies [Last post]
ajwreinhardt
Offline
Joined: 2008-11-22
Points: 0

Hi. I am trying to work on the Java Tutorial as a beginning programmer...and I no matter what I try to do cannot seem to get my thing to accept this method I'm trying to create for a class. Here's an example of my method:

void changeProc (int newValue) (
gear = newValue ;
)

I have tried this and several variations several times but I cannot get it to work...I get two different errors from the NetBeans IDE:

1. "Missing body method, or declare abstract. ';' Expected" Ok, I did declare the body method right? The "gear = newValue"? And I do have a semi colon at the end of the body code.
2. "Illegal start of type" on the second line where the "gear = newValue" is.

The tutorial hasn't offered any help...I would appreciate some assistance. Thanks.

Jake

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
raychamp
Offline
Joined: 2008-11-25
Points: 0

the method body needs to be surrounded by "{}" not "()"

jhipp117
Offline
Joined: 2008-08-24
Points: 0

It's difficult to diagnose what you did wrong without seeing the code that
went before.

However, the following worked for me:

public class JHTest {

int gear=1;

void changeProc(int newValue) {

gear = newValue ;

}

}

JHipp