encapsulation -- the formal defn means , code and data put together is encpsulation ,so some if class A inherits class B .Then class A cannot modify the datat that is present in class B , it can only use the methods of class B to access the datat of class A
eg : a superclass object could be used to invoke a overriding method of the sub-class and the same superclass object could be used to invoke the overridden method in the superclass
Originally posted by bhavesh bhanushali:
yes u can call a sub class method with a super class object
yes u can call a sub class method with a super class object ( that is what is runtime polymorphism ), in the example above i ahve given a example of the same
Originally posted by rathi ji:
The proper definition will be " Make attribute private and provide public accessor (getter and setter) method to access them is encapsulation "
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Accessors still break encapsulation - not as much as public fields, but they still do. Objects should expose behaviour, not data.
Originally posted by rathi ji:
(If we are providing constructor for this, then it is as good as providing 'setter method')
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by rathi ji:
Hi Jacquie,
There are 3 basic features of object oriented programming language:
Inheritance
Polymorphism
Encapsulation
Could you please explain polymorphism with code. What will be the proper answer, if it is asked in interview.
Thanks a lot.
Consider Paul's rocket mass heater. |