Super keyword

when we override any method then to call the base class overridden function where should we write super().

Is it compulsory to write it in first line after variable deceleration.

No, it is not compulsory to write the super() in the first line. You may call it a whatever the place in your overriden method. For example you may want to do some extra job before calling the parent class method’s functionality. void myMethod() { ; this.validateSomething(); super(); this.updateSomethingElse(); }

in the ax we can declare all the variables first only not possible any were in the method

call super first or end of method that means after variables declaration

public void init()

{

int a;

int b;

str c;

;

super();

//write here your code

}

= ANYWHERE in the code after variables declaration (not just at the beginning or end).

Thanx Janis and Chandra…i asked this question coz in some methods like init() , when i wrote super() elsewhere in code then it was not working properly. Moreover i learned in java that super() should be used in first line of subclass method.

Bt in some other methods when we write super() in any line of method then it works.

The reason why call of super() might fail if it is being placed in different places in the method is based purely on the current logic of code… there are no restrictions from X++ syntaxis point of view.

Let’s say for the init() example - if you haven’t called super() yet, then some essential values might not have been initialised, but your code in the child method already expects those values to be initialised… if the parent class method is supposed to do something crucial and this hasn’t been performed yet, then it is obvious that child method might have problems with it’s own code execution expecting that things are already prepared by parent class.

ya

any where in code after variables declaration

depends on code