简体   繁体   中英

how to pass to argument to parent class from grand child class or sub class

I am having parent class P that has constructor in it with an argument. I am having child class C that extends P and then I am having another sub child class Sc that extends C .

for example

parent class

class P {

    Settings settings

    public P(Settings settings) {
        this.settings = settings
    }
}

class C extends P {

  Settings settings

   public C(Settings settings) {
   super(settings)
   this.settings = settings
  }
}

class Sc extends C {

      Settings settings

       public Sc(Settings settings) {
       super(settings)
       this.settings = settings
      }
    }

here I am able to pass the argument to the constructor from class C to class P but not from class Sc to class c and to class P. how can I pass argument to the super class from grand child class ?

You can call

super(setting)

in your child constructor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM