I'm learning OOP and java with an online-course. This chapter is about access modifiers and you have to call every possible attribute of TestRobot.
Now I've tried it with an array of the attributes and wanted to use a for-loop to check them all if they exist. Of course, I could just do it 4 times but this is redundant somehow. :D Now I have an error that there is no symbol attributes. My suggestion is that the compiler is checking in the class robots for "attributes".
Is there a possibility to tell java that attributes is an array or variable of the class Terminal instead part of the class robot itself? For example in JavaScript you would just write robots[attributes[i]].
Is it even possible to call EVERY attribute of a class?
class TestRobot {
private int secretKey = 602413;
protected int numberOfProcessorCores = 4;
boolean hasFirewall = false;
public String id = "58-08-2";
}
class Terminal {
String[] attributes = {"secretKey", "numberOfProcessorCores", "hasFirewall", "id"};
public void hackRobot(TestRobot robot) {
for(int i = 0; i < attributes.length; i++){
if(robot.attributes[i]) {
System.out.println(attributes[i]);
}
}
}
}