Java Programming

Object Oriented Programming(OOPs) Concept

In this article, we’ll explain what is Object Oriented Programming(OOPs) Concept.

An object is an entity which has a well defined structured & behavior. An object is a real world entity such as pen, chair, table, etc. An object is run-time entry. It can be tangible, intangible or conceptual. For example:- Air, sound, HD, person, bank account.

What is Object Oriented Programming(OOPs) Concept

Tangible object is something than can be felt by touch & can be seen. For example:- If we are defining an object if sofa java class then it is tangible since sofa is something that you can feel by touch.

Intangible object is one which we cannot touch & see. For example:- Time Java class object has/would have state as well as behavior, but cannot be felt by touch.

A conceptual system is a system that is composed of non-physical objects i.e. ideas or concept.

Object contains certain characteristics as:

  • State(attribute)
  • Behavior(functions)
  • Identity(unique identity)
  • Responsibility(role)

State of an object:

Attributes/includes current values of all its attributes. An attribute can be state & dynamic. Non-changing attributes are known as static attributes, changing attributes are known as dynamic attribute.

For example:

1. Employee Attributes

  • Static
    • empId
    • name
    • gender
  • Dynamic
    • age
    • salary
    • phoneNo
    • address
    • education
    • experience

2. Window as an object

Height, width, background color & the co-ordinates of a window can be its attributes.

Behavior of the object

Behavior is how an object act & reacts in terms of its state changes & message passing. Behavior of object corresponds to function. For ex: calculatesalary() & printdetails() are behavior of Employee.

Window object change whenever resized, minimized of maximized. Similarly, fan when speed regulated or turned ON/OFF. Again, charging the battery of monbile phone would change the state of the battery at a given point of time.

Identity of the object

Identity is that property of an object which distinguishes it from all other objects. For ex:

  1. empId is an identity of employee. No two employeewill have same empNo.
  2. Fan & mobile no. would have a unique product no. as an identity.

Responsibility of an object

Is role it servers within the system. For ex: Responsibility of employee is to carry out the work given & get the salary.

Class

A class comes from the word called classification. An object is instance of class. Class used to map real word entities into data members & member function. It is a logical entity. Class is a keyword which is used to declare a class.

Class in Java contain:

  • Field
  • Method
  • Constructors
  • Blocks
  • Nested class & interface.

Key concepts of OOP are:

1. Abstraction:

It is the process of identifying the key aspects & ignoring the rest. Only those aspects are selected that are important to current problem scenario. Achieved by abstract class & interface.

2. Encapsulation:

Mechanism used to hide the data, internal structure & implementation details of an object (Hiding internal details & showing functionality). data hiding ensure security of data. Can be achieved through access modifiers. It is a good practice to make data members as private & member functions as public. Ex. Phone call, we don’t no internal processing.

3. Inheritance:

Inheritance is the process in which one object acquires the properties & behavior of another object(parent object). It provides code re-usability. It is used to achieve run-time polymorphism. “is-a” kind of hierarchy.

Inheritance:(Generalization & Specialization)

Generalization:

Moving up in hierarchy is said to be generalization requires good skill of abstraction. The topmost class in the hierarchy is the most generalized class. Generalization is extracting shared characteristics from two or more individual classes & combining them all into one ” generalized” superclass.

Specialization:

Moving down the hierarchy more & more specific features are added in subcategory that is formed. This is said to be specialization.

Example: A bank account is of two types- current account and saving account. Current and saving account inherits the common/generalized properties like account no. & account balance etc. from bank account & also have their own specialized properties like interest rate etc.

In this article, we have explained what is Object Oriented Programming(OOPs) Concept.

Get high performance Intel Xeon duel E5 series server and KVM VPS instantly.

Related Articles