Results 1 to 3 of 3
- 11-18-2007, 02:01 AM #1
Member
- Join Date
- Nov 2007
- Posts
- 2
- Rep Power
- 0
Im new to java. how do i fix the problem with class
im just new to java. my problem is, i copy and paste a code from java.sun.com to a notepad, i save it as class.java.
the code is:
private class Bicycle {
private int cadence;
private int gear;
private int speed;
public Bicycle(int startCadence, int startSpeed, int startGear) {
gear = startGear;
cadence = startCadence;
speed = startSpeed;
}
public int getCadence() {
return cadence;
}
public void setCadence(int newValue) {
cadence = newValue;
}
public int getGear() {
return gear;
}
public void setGear(int newValue) {
gear = newValue;
}
public int getSpeed() {
return speed;
}
public void applyBrake(int decrement) {
speed -= decrement;
}
public void speedUp(int increment) {
speed += increment;
}
}

what seems to be the problem???
- 11-18-2007, 02:04 AM #2
Member
- Join Date
- Nov 2007
- Posts
- 2
- Rep Power
- 0
it always happen in the line of
"public class ClassName{}"
even in other sample program. as long "public class ClassName" exist in the program, it always has a error. why?? please help.
- 11-18-2007, 04:47 AM #3
The class name that has the public modifier (and that usually contains the main method) in your source file must have the same name as the file name.
So if you pasted the class into an empty document and change (the access modifier [private to public] in the) the class signature to:
Now you save the document as "Bicycle.java" This file name that you save it as must be the same as the name of the class - case is important. Then you compile it with:Java Code:public class Bicycle
Press enter.Java Code:javac Bicycle.java
You should see a class file appear in the current directory.
Run it with:
Press enter.Java Code:java Bicycle
Since you do not have a main method in the class you should see something like this in the console:
Java Code:C:\java\bin>java Bicycle Exception in thread "main" java.lang.NoSuchMethodError: main
Similar Threads
-
problem in wrapper class
By binoympappachen in forum New To JavaReplies: 4Last Post: 12-13-2007, 12:31 PM -
Class problem
By Deagel in forum New To JavaReplies: 1Last Post: 10-31-2007, 07:33 PM -
Problem calling another class
By adlb1300 in forum New To JavaReplies: 3Last Post: 10-25-2007, 02:05 PM -
problem with date class
By gabriel in forum New To JavaReplies: 3Last Post: 08-03-2007, 01:28 PM -
problem with scanner class:incompatible types
By fred in forum New To JavaReplies: 1Last Post: 07-20-2007, 07:02 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks