class Machine {
int info1 = 7;
public void show(){
System.out.println(info1);
}
}
class Camera extends Machine {
int info1 = 13;
}
public class Application{
public static void main(String[] args) {
Machine combo = new Camera();
combo.show();
}
}
From my understanding, I've created an Object called combo by instantiating the class of Camera, but am using the variable type of Machine, which is the superclass of Camera.
Now, since I'm creating an Object of Camera, I expect the method show() to print 13, but this code instead prints 7, as declared in the superclass Machine. I realize that the variable type of Machine confers the reference variable combo the method show(), but shouldn't the value return 13 since the Object itself is an instance of Camera? Thank you in advance for your help!
showis not in the scope of theCameraclass.info1field. (a thing that Java should really not let you do in the first place)show.why does 13 not print?You can answer that question in two ways: I chose to look at it from one perspective.