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 ...

Get Learning Java by Building Android Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.