header ads

Java OOP - A simple introduction

Object oriented programming (OOP) is a mechanism of programming based on concept of objects. Let's discuss this using an real world example.

Object: Car

Car object has attributes: Brand, Model, Year. These can be identified as fields in java. (i.e. public constants or public variables).

Car object has methods: Drive, Brake, Accelerate, Reverse. These can be identified as methods in java.

Car object has events: on brake (during brake event - should reduce speed). These are same as events in java.

to obtain OOP concept in java programming we use following mechanisms.

Inheritance - Acquiring variables and methods from parent class. (parent-child relationship)

Polymorphism - Perform same task in many ways (method overriding and overloading)

Abstraction - Hide internal process of a particular class and show only the output

Encapsulation - Dividing complex functionalities (codes) to smaller units (classes and methods)

The primary goals of the OOP concept are to reduce the code complexity and increase the re usability. Next i'm going to explain all above mechanisms using simple examples from my upcoming tutorials. Like our facebook page and share this article among friends.

Post a Comment