Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java super() inheritance

A short summary of the question: I have a parent class which is extended by a child class.

     public class Parent{

        public Parent(){
          //constructor logic
        }
     }

This child class calls the Parent's constructor using super:

     public class Child extends Parent{

         public Child(){
            super();
         }
     }

I was wondering if I were to extend the Child class if I could call the super() method in the Grandchild class' constructor:

    public class Grandchild extends Child{

         public Grandchild(){
            super();
         }
    }
like image 695
Thoross Avatar asked Aug 01 '26 02:08

Thoross


1 Answers

That would call the Child class constructor, which in turn will call the Parent class constructor.

like image 199
Kazekage Gaara Avatar answered Aug 02 '26 14:08

Kazekage Gaara