I’m trying to make a new “Time” class,
time.java
public class Time{
public int hour,minute;
public double second;
public Time(){
super();
}
}
main_activity.java
Time newT = new Time();
newT.hour = 3;
but i get an error here: newT.hour
error (in eclipse) “Syntax Error on token “hour”, Variabledeclaratorid Expected after this token”
The accessibiliy of hour is
private, so you cannot access it from another class. Create setters and getters:Now set it via
newT.setHour(3);Edit: I see you reworked the errors. The actual error is because you have put these lines
in the class body, I assume you have something like this:
But you cannot do such a thing, as you may only declare variables/methods/classes in your class body. Try this: