Search code examples
androidinheritancesubclasssuperclass

Subclasses and inheritance


Let's have I have 3 classes. The First one is the parent class, The second one is a subclass of the Parent class. And the third class is a extends the 2nd class, which is a subclass itself. Will the 3rd class inherit the methods from the parent class?


Solution

  • Best example could be the class all Android developers know : Activity.

    The doc clearly says that Activity extends ContextThemeWrapper which extends ContextWrapper which extends Context which extends Object.

    Object class has ".toString()" method. So, try to print in your console any object you instantiate (like your main Activity) to see the result !

    Everything is Object in Java.

    Now you know. :)