Friday, June 4, 2010

Object oriented Java

I have updated in http://www.freejavaclass.com/
The Object Oriented Programming Languages directly represent the real life objects like Car, Jeep, Account, Customer etc. The features of the OO programming languages like polymorphism, inheritance and encapsulation make it powerful. [Tip: remember pie which, stands for Polymorphism, Inheritance and Encapsulation are the 3 pillars of OOPL]



Inheritance: The main purpose of inheritance is code reusability. In java we can achieve this by two ways,


• You can achieve inheritance as well polymorphism in is-a relationship.
• In has-a relationship you can achieve code reusability but can’t achieve polymorphism, the one way to achieve polymorphism is use interface implementation in your design.

Polymorphism: The ability of one object reference will hold the address of another object in the same inheritance hierarchy and capable of executing the method in the address holding object at runtime. The benefit of polymorphism is that it is very easy to add new classes of derived objects without breaking the calling code.

Encapsulation: Refers to keeping all the related members (variables and methods) together in an object. Being able to encapsulate members of a class is important for security and integrity and also improves code modularity by preventing objects interacting with each other in an unexpected way.

No comments:

Post a Comment

How can instantiate Java interface without implementing.

public interface Foo { String method(); } public class Claaa {    public static void main(String[] args) {     Foo fooByIC...