OOP Concept

This tutorial will help you to understand about Java OOP’S concepts with examples. Let’s discuss what are the features of Object Oriented Programming. Writing object-oriented programs involves creating classes, creating objects from those classes, and creating applications, which are stand-alone executable programs that use those objects. 

A class is a template, blueprint,or contract that defines what an object’s data fields and methods will be. An object is an instance of a class. A Java class uses variables to define data fields and methods to define actions.A constructor can perform any action, but constructors are designed to perform initializing actions, such as initializing the data fields of objects. 

To understand OOPs concept better let’s take the example of Mobile as an object. Mobile has characteristics like a model, manufacturer, cost, operating system etc. So if we create “Samsung” mobile object and “IPhone” mobile object we can distinguish them from characteristics. The values of the attributes of an object are also referred to as the object’s state.

There are four main features of OOPS.
  1. Abstraction 
  2. Encapsulation
  3. Inheritance
  4. Polymorphism
Abstraction :
   In java, the Abstraction is hiding the complexity of workflow from the end user.
abstraction is implemented with the help of the class, objects, and variables that can represent complex underlying code and data. Abstraction eliminated the need for new code creation every time and increases code reusability.

In order to implement abstraction, Java programmers create reusable and useful tools. Like several objects that may have variables, functions, and data structures can be created. Different classes to create the objects can also be created by the programmers.

Encapsulation
   Wrapping up(combing) of data(variable) and functions(method) into a single unit(class) is known as encapsulation. It also means hiding data and methods within an Object. Only the class methods can access the class data. Outside of class methods can not access the data members of another class. It provide the security of class data members and class methods. Encapsulation provides the security that keeps data and methods safe from inadvertent(needless) changes.
Inheritance
   An important feature of object-oriented programs is inheritance—the ability to create classes that share the attributes and methods of existing classes, but with more specific features. Inheritance is mainly used for code reusability. So you are making use of already written the classes and further extending on that. That why we discussed the code reusability the concept. In general one line definition, we can tell that deriving a new class from existing class, it’s called as Inheritance.

Polymorphism   In Core, Java Polymorphism is one of easy concept to understand. Polymorphism definition is that Poly means many and morphos means forms.  polymorphism means ability to take more than one form. An operation may exhibit different behaviors in different instances. The behavior depends upon the types of data used in the operation.