Hello,
maybe I’m getting confused but I was expecting for this print line to return an error since I’m trying to access a private field (age) from outside its class (Parent)? Thanks
class Parent{
private int age;
public Parent(int age){
this.age = age;
}
}
class Child extends Parent{
private String name;
public Child(String name, int age){
super(age);
this.name = name;
}
}
void setup(){
Child c = new Child("Tom", 4);
Parent p = new Parent(40);
println("C: " + c.name + " - " + p.age); //I was expecting p.age to not work
}