Wednesday 28 August 2013

Use of IIB , SIB ,Constructor overloading , Inheritance.

we had seen  all these features in previous articles...
now we will use all of these in single program and see what changes occurs .....

Constructor ,SIB , IIB will not be inherited to subclass.we cannot inherit all of these freatures but we call it how just see the examples...

in inheritance the constructor contains the default statement:-
super();//constructor with no arguments..it presents as the first statement by default..

Example:-



here you have seen that we didn't call the constructor of  X.so in the Y constructor the default statement is
super();//which calls the super class constructor .it is called by the super() statement  not inherited to class Y.

if in the super class no arg constructor is not present it will give compile time error

example:-


so i think you will understand the reason.

super() and this() must be the first statement of the constructor otherwise it will give compile time error
we cannot use super and this statement together in 1 constructor .we use only one statement.




Example :-



so first sib executes only once then iib then constructor.....




No comments :

Post a Comment