So I can run my code from cmd, I edit using sublime text, but now I´m required to use Visual Code Studio and this software can´t seem to call any subclass porperties from the main method, Visual Code can't seem to handle this line: (Healer)n.get(i)).getHealer()
When I use the subclass getter it doesnt give an error message, however when I try to create an object for the subclass I get the following: "The public type Healer must be defined in its own file"
// n is an ArrayList with objects and this iteration is in the superclass
for(int i = 0; i<= n.size()-1; i++){
if(Healer.class.isInstance(n.get(i))){
System.out.println(((Healer)n.get(i)).getHealer());
}
}
// and here's the constructor for the subclass that I'm calling from the superclass
public class Healer extends Hero{
int healer;
Healer(String c, String a, String b, int d, int e, int o){
super(c,a,b,d,e);
this.setHealer(o);
}
public void setHealer(int o){
this.healer = o;
}
public int getHealer(){
return healer;
}
}
This has nothing to do with Visual Studio Code and everything to do with the rules of Java. The error message is very clear about what you need to do:
The public type Healer must be defined in its own file
Either put class Healer
in its own file or remove the public
modifier.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments