More about OOP and classes
It is possible to write a whole book on OOP, and many authors have already done so, but the best way to learn OOP is probably to practice it; practice it before we have learned all of the theory. Anyway, before we get on with some more practical examples, here is one more slightly theoretical OOP example that will leave us scratching our heads later if not mentioned.
Inner classes
When we looked at our basic classes demo app, we declared and implemented the class in a separate file to our MainActivity
class. That file had the same name as the class.
We can also declare and implement a class within a class. The only question remaining, of course, is why would we do this? When we implement an inner class, the inner class can access the member variables of the enclosing class and the enclosing class can access the members of the inner class. We will see this in action in the next two chapters.
If you are not modeling deep or real-world systems, then inner classes are...