Re: Why won't this compile?
Code:
class Transmission{
public enum GearState{neutral,first,second,third,fourth,fifth}; // first letter of a variable shouldn't be a digit
private GearState currentgear=GearState.neutral; // type mismatch if we use a non GearState identifier
public void setGear(GearState gs){
currentgear=gs;
}
public GearState getNextGear(){
return currentgear; // why don't we just return the current gear state?
}
public void printGears(){
for(GearState gs:GearState.values()){
System.out.println(gs);
}
}
}
public class test{
public static void main(String[] args){
Transmission t=new Transmission();
System.out.println(t.getNextGear());
t.setGear(Transmission.GearState.first);
System.out.println(t.getNextGear());
}
}
Re: Why won't this compile?
Opps i forgot that they are identifers. :lol: With the getNextGear() method i asked myself the same thing. I was going by an article from a november issue of jdj volume: 9 issue :11.