0
Declare a constant variable in java
Hi guys please help me My task is to declare a constant variable COURSE with value PROG1 in the class. The constant should be visibel outside the class. public class AClass{// this is fixed i guess static final String COURSE= ”PROG1” Public String toString () {//this is fixed I guess Return COURSE; } } But i get nosuchfieldexception :COURSE It expected true test Try { java.lang.reflexer.Field f= AClass.getfield(COURSE ”); Modifier is final something
4 Respostas
+ 2
declare it public?
public static final String COURSE = "PROG1";
0
I tried it didn’t help
0
full code? How are you testing it?
0
ok, I didn't notice it, but public and return should not be capitalized.
public class Program {
public static void main(String[] args){
AClass a = new AClass();
System.out.println(a.toString());
System.out.println(AClass.COURSE);
}
}
public class AClass{
public static final String COURSE= "PROG1";
public String toString(){
return COURSE;
}
}