The six OOP principles are as follows :
- Objects.
- Class.
- Inheritance.
- Encapsulation.
- Polymorphism.
- Abstraction.
Now what are these? Let us take a look at them.
- Object : Object is anything that we create using a program. All the objects (whether made by a program or in the real world) have two main characteristics : State and Behaviour. Let us take the example of a car. A car has state i.e. its characteristics, for example colour, size, and shape and behaviour i.e. what it does, for example running, turning at curves, etc. Similarly, objects have there state or values in the variables and they behave according to the instructions given by the methods contained in them. This combination of state and behaviour i.e. variables and methods is known as an object.
- Class : A class is the prototype or the blueprint of the objects and contains the methods and the variables that define the state and behaviour of the object. It is just like a blueprint of the construction of a robot. It contains the information how to construct a robot. Just as the single blueprint can be used to make many similar robots, a particular class can be used to create a number of objects similar in characteristics.
- Inheritance : It is the process by which an object or even a class can acquire or "inherit" the properties of other objects and classes respectively. It can be used to derive a class from another class here the derived class is called the sub-class or the child-class and the class from which it is derived is called the base-class or parent-class. There are two kinds of inheritance in Java : 1. Simple Inheritance. 2. Multilevel Inheritance.
- Encapsulation : It is the process of binding the Code and Data within a capsule to prevent any misuse of the data and the commands within the program though the user can interact with it through a interface. Here the capsule is the class which prevents the access to the code through access specifiers (public, private, protected). For example we cannot change the inside contents of a music player but we can interact with it by pressing the buttons on it. Similarly, we can interact with a program by giving values to the variables through methods but we can't edit its contents until we are granted access to it.
- Polymorphism : Polymorphism is the ability of an action or method to do different things based upon the object on which it is acting. This is the third OOP principle. The different types of polymorphism are as follows : Overloading, Overriding, Dynamic method binding.
- Abstraction : Hiding unnecessary details and showing the essential features is called abstraction.
No comments:
Post a Comment