import - Enum can not be resolved? Java -
i have 2 classed @ different pages.
the object class:
public class sensor { type type; public static enum type { prox,sonar,inf,camera,temp; } public sensor(type type) { this.type=type; } public void tellit() { switch(type) { case prox: system.out.println("the type of sensor proximity"); break; case sonar: system.out.println("the type of sensor sonar"); break; case inf: system.out.println("the type of sensor infrared"); break; case camera: system.out.println("the type of sensor camera"); break; case temp: system.out.println("the type of sensor temperature"); break; } } public static void main(string[] args) { sensor sun=new sensor(type.camera); sun.tellit(); } }
main class:
import sensor.type; public class mainclass { public static void main(string[] args) { sensor sun=new sensor(type.sonar); sun.tellit(); }
errors two, 1 type can not resolved other cant not import. can do? first time used enums see.
enums
required declared in package import
statements work, i.e. importing enums
classes in package-private (default package) classes not possible. move enum package
import static my.package.sensor.type; ... sensor sun = new sensor(type.sonar);
alternatively can use qualified enum
sensor sun = new sensor(sensor.type.sonar);
without import statement
Comments
Post a Comment