Data overriding is when u want to override a method of base class in your derived class. In this whenever you create an object and call the method derived class method will be called , irrespective of what you are using on left hand side (base class name or derived class name). ie
In both these cases the method Calc of derived class will be called, or you can say derived class method will always override base class method. And the result would be
Data Hiding
In data hiding, you hide the base class method, and define a new method. Now the new method )in derived class) will be called only if the object is of derived class type (on left hand side also).
The output is,
In both these cases the method Calc of derived class will be called, or you can say derived class method will always override base class method. And the result would be
Data Hiding
In data hiding, you hide the base class method, and define a new method. Now the new method )in derived class) will be called only if the object is of derived class type (on left hand side also).
The output is,
Result: 28.26
Reult: 12
Reult: 12
Result: 28.26
Result: 7
Result: 7
No comments:
Post a Comment