OOPs concepts in java

In this post, we will study about the OOPs concepts i.e. Objects oriented programming concepts. As per its name, first question comes to the mind is what is an object?

What is an Object?

OK, so you will also find objects around you. In real world scenario, We can say everything is an object like car, fan, pen etc.An object has 2 characteristic i.e. State and behavior and it can be physical and logical. Let’s understand with examples.

A car has a state (name, color,model etc.) and behavior (driving,applying break, horn etc). Same way pen has a state (amount of ink,lid with on and off feature) and behavior (can be used to write etc.). These are the physical entities.

If we talk about non-physical things or logical objects, you can consider your bank account. A bank account can not be touched physically but has a state (the amount of money in it) and behavior ( depositing or withdrawing money).

How does it relate to the programming model?

Object oriented programming is programming that involves intellectual objects that helps us to achieve or resolve business problems in real world.

In real world, you will find many objects of the same kind. There are many cars in the world, but each car is built from same set of blueprints and have same components.Class is a blueprint, from which individual objects are created.Consider a class name as CARS, Your car A is an instance of the class CARS , similar way your neighbor’s car B is also instance of the class CARS.

Class Objects

 

Object oriented programming has some fundamentals principles which help to simplify the software development and provides re-usability and maintainability.These are as follows:

  • Inheritance
  • Polymorphism
  • Encapsulation
  • Abstraction

Inheritance: When an object in a child class acquires properties from objects in the parent class known as Inheritance. It improves code re-usability. There can be different types of cars like sports cars, small cars, big cars etc., which acquire properties from their parent class CARS.

Car model

 

Polymorphism: If an object is capable to take many forms, is known as polymorphic. Consider a class called Shape. Shape can be anything like rectangular, circle, square etc. Polymorphism can be achieved by overloading and overriding of the methods. We will study about overriding and overloading in details in later posts.

Shape

Abstraction: Abstraction shows functionality and hides irrelevant details that would confuse us. As an example, watching TV. User is concerned about switch the TV On and Off to watch desired shows and not bothered about its internal logic how it is displaying.

Tv

Encapsulation: Encapsulation is use to control the access to data from outside class ,also known as data hiding.Data and code will be combined in single unit. It improves maintainability, flexibility and re-usability.

Difference between Object oriented programming and object based programming:

Object based programming language contains all the features of OOPs except Inheritance. JavaScript and VBScript are examples of object based programming languages.

Ask Question
If you have any question, you can go to menu ‘Features -> Q&A forum-> Ask Question’ .Select the desired category and post your question.
Print Friendly, PDF & Email
Operators in java
Naming convention in Java
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. He is an automation engineer having more than 8 years of experience who loves troubleshooting in automation and finding innovative ways to solve the problems. His other leisurely activities includes playing harmonica, paintings, sketching portrait, watching movies and travelling etc.

You may also like...