Java – Object Oriented Programming

Java – Object Oriented Programming 2017-08-14T13:39:45+00:00

Object Oriented Programming Concept

Learning about Class, Object, Component, Encapsulation, Inheritance, Polymorphism & Object Creation and Instantiation all about Object Oriented Programming Concept.

Class: A class is a one kind of template, skeleton or we can say blueprint for creating an object.
1. What is an Object?
2. What is NOT an Object?
Definition: An Object is an entity that has Properties for identifying its State, Methods for Behavior and Events for depicting the Change of State.
Data associated at any given instance of time is the state of an object.
Every object will different from other objects either by state or behavior.
Object has a lifetime – It’s created, used and destroyed.
Object Oriented Application: It’s a collection of related objects, communicating with each other, exchanging messages with each other in a controlled environment as per the rules of the business.
Component: A ready to use third party object can be called as a Component. It can be replaced without any changes in the application. A component is generally used by a programmer as an object.
Loosely coupled objects are better than tightly coupled objects i.e. the lesser the information given to other objects the better it is as the objects are loosely coupled the dependencies are less and stronger security.
Every object oriented language should have three features:
1. Encapsulation
2. Inheritance
3. Polymorphism
1. Encapsulation: Binding of data and behavior i.e. functionality of an object within a secured and controlled environment is encapsulation.
1. Data Hiding / Abstraction.
2. Implementation Abstraction
3. Makes the class simpler to use.
4. Loose Coupling
2. Inheritance: The Process of acquiring the existing functionality of the parent and with new added features and functionality by a child object is called inheritance.
The advantages of inheritance are Generalization, Extensibility and Reusability.
For example: A calculator is a generalized form of mathematical operations where as a Scientific calculator is an Extended and Specific form.
Some more examples of Inheritance
Car is a Vehicle
Faculty is a Person
Student is a Person
Mango is a Fruit
Chair is a Furniture
Scientific Calculator is a Calculator
Kinds of Relationship between objects:
a. is a – Depicts Inheritance – Two Classes must be related.
b. has a – Depicts Containment – Two Classes must be related
c. type of / instance of – A class and object is related.
3. Polymorphism: “Poly” means “many” and “morph” means “form”.
An object in different forms and in each form it exhibits the same functionality but implemented in different ways.
A parent class variable taking the form of child class objects and using this variable invoking the functionality of object this variable has actually taken the form (either of the child class object)
A Teacher can take a form of Sport Teacher or Language Teacher and in both the forms it has the functionality Teach, but the implementation of Teach varies in both the objects and depends.
Vehicle – Car or Scooter – Drive
Phone – Mobile Phone or Landline Phone – Speak
Database – Oracle or Sql Server – Write
Figure – Circle or Square – Area

Prev Next