1
votes

The class LabelField has a method -

public void setPadding(int, int, int, int);

If I create a class that extends LabelField overriding setPadding like so -

public class CustomPadding extends LabelField {

    public void setPadding(int, int, int, int){
      super.setpadding(5,5,5,5);
    }
}

Every time I create an instance of CustomPadding shouldn't my custom setPadding method be called ?

Currently it is not, I'm not sure why ?

2

2 Answers

3
votes

Why would anything automatically be calling the setPadding method? It won't be called automatically - something has to actually call it, explicitly. Do you have any reason to believe that something in the constructor chain for LabelField calls it?

If you're trying to make customPadding (which should be named in PascalCase, btw) always set its padding in a particular way, you should call it from the constructor.

1
votes

should'nt my custom setPadding method be called ?

Not if the original setPadding wasn't called in the first place.

I.e., the answer is, yes, customPadding.setPadding should be called whenever LabelField.setPadding would have been called if it was a LabelField. (But if LabelField.setPadding wouldn't have been called, neither should customPadding.setPadding.)

You should provide a bit more code. (I for instance assume you actually have names for your parameters in customPadding.)