Object Oriented Programming(OOP) in Java

Ravindu Akalanka
3 min readJan 6, 2023

--

Object-oriented programming is created from paradigmatic concepts like inheritance, data binding, and polymorphism. The first object-oriented programming language was Simula. An object-oriented programming language is a programming model that represents everything as an object. Examples of object-oriented programming languages include Java, C#, Python, and C++.

An object means a real-world object. (e.g., table, book, pen) Designing computer programs using classes and objects is called object-oriented programming. This helps a lot in software production, development, and maintenance.

These are the main concepts of object-oriented programming.

  1. Object & Class
  2. Inheritance
  3. Polymorphism
  4. Abstraction
  5. Encapsulation

1. Object & Class

i. Object

Anything that has a state and behavior in the real world is called an object. An object can also be defined as an instance of a class. The characteristics of an object are that it contains an address and takes up space in memory.

ii. class

A class is a collection of objects. It is also called a logical object. A class takes up no space in memory. A class is also defined as a blueprint for creating an object.

2.Inheritance

Inheritance is the complete transmission of the variables and methods of one class to a new class derived from another. The first class is called the superclass, and the new class is called the subclass. A subclass can have its own variables and methods.

An example from Java,

3.Abstraction

Abstraction is the separation of only the necessary data from a large amount of data contained in an object. For example, let’s consider an online banking application. A large amount of data has been received from a customer, as shown below.

These data F.Name, NIC, Mobile Number, Address, Salary Information, and Tax Information — are important for an online banking application. Abstraction is the separation of only the necessary data.

4.Polymorphism

If each task is performed in different ways, it is called polymorphism. An example could be talking about something. Pusaku “Meow…!” And a duck can be pronounced "quack,” and a dog “woof.”

In Java, after overriding a method of a superclass in a subclass, upcasting and running a subclass method through a superclass reference is polymorphism.

5.Encapsulation

Binding code and data together into a single unit is called encapsulation. An example is a capsule. It is packed with different types of drugs.

A Java class is another example of encapsulation. Here, data is protected.

--

--