Thursday, September 1, 2011

Basic concepts of Object Oriented Programming


In Object Oriented Programming the problem is divided into objects and then build data and functions around these objects. The combination of data and functions make up an object.

The data of an object can be accessed only by the functions associated with the object.

What is class

Most languages offer primitive data types like: - int, long, float etc. Their data representations and response to different operators are defined as a part of the language. The language does not know user defined data types. The programmer defines its format and behavior by defining a class. So, a class is a user defined new data type, which serves as a template, and an object is an instance of a class. It specifies what data and functions will be included in objects of the class. A class may be thought of a data type and an object as a variable of that data type. Once a class has been defined we can create any number of objects of that class.

Main features of object oriented programming

1. Encapsulation: - The wrapping up of data and function into a single unit (called object) is called encapsulation. The data is not accessible to the outside world and only those functions, which are wrapped in the class, can access it.

2. Inheritance: - This is a mechanism by which one object acquires the properties of another object of different class. Inheritance is probably the most powerful feature of object-oriented programming. Inheritance is the process of creating new classes, called derived or sub classes from existing classes. The existing classes are called base or super classes. In OOP, the concept of inheritance provides the idea of reusability. This means that we can add additional features to an existing class without modifying it. This is possible by deriving a new class from the existing one.

3. Polymorphism: - This is another OPP concept. It means ‘many forms’ i.e. the ability to take more than one form. For example, an operation can exhibit different behavior in different situation.

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner