I am new to Java, need some help
I have an abstract superclass that has 2 protected attributes
public abstract class Superclass {
protected int a = 0;
protected int b = 0;
...
}
then I have a subclass that extends the superclass, and i wish to access a and b, but I dont know how. I searched the web and didnt find anything.
public class Subclass extends Superclass {
public boolean someMethod(){
.....
// at the end i need to do
a += 1;
return true
}
}
I get the compilation error: "unreachable statemen"
thanks for your help.
"Unreachable statement" means that there is no path in your code that can get you to this line in your program. It has nothing to do with protected fields. Check, if there is a return
statement before your a+=1
that always exits your method before this line is ever reached. Or, if your a+=1
is in an if
-block that is never executed, because the condition you specified always evaluates to false
.