Martin Müller wrote:Doesn't the AccessModifier of the above variable in the Egg class, Ch. 1, p. 20 have to be public? Otherwise the main class can't directly print it and a getNumber() method would be needed.
No, that's not required because the main method is defined in the Egg class as well. And every method defined in a class can access other private members (variables and methods). It would be true if the main method (accessing the number variable) was defined in another class (e.g. TestEgg).
Let me share the complete code snippet so everyone can join this discussion