Java Object Oriented Programming Concepts - The Coding Shala

Home >> Learn Java >> Java OOPs Concepts

Java Object-Oriented Programming(OOPs)Concepts

In this post, we will discuss the basic concepts of object-oriented programming. First, we will see what is Object Oriented Programming then discuss its concepts.
Java Object Oriented Concepts - The Coding Shala

Object-Oriented Programming

Object means a real-world entity like a pen, computer, car, etc. Object-Oriented Programming or OOPs uses objects in programming. The following are concepts of OOPs:
  • Object
  • Class
  • Method
  • Inheritance
  • Polymorphism
  • Abstraction
  • Encapsulation
In this post, we will discuss a basic overview of these concepts.

Objects

An object is a basic unit of Object-Oriented Programming. It represents real-life entities like computers, cars, tables, etc. When we create a class, Object can be defined as an instance of that class. When we define an object, it contains an address and takes up space in memory.

Objects have identity, Behavior, and State. For example, dog an object then the name of the dog is identity. Age, color, the breed are dog's state. the dog can eat, sleep and bark. These are dog behaviors.

Class


A class is a user-defined blueprint or prototype. A class contains a logical part of the code in the form of methods. we create objects for the class to access this logic of class.
Point to Remember: Class doesn't consume any space, Objects do.

Method


We write a method inside the class. A method is a collection of statements that perform some specific task. In Java, every method must be part of some class.

Inheritance


Inheritance is an important property of OOPs. When we write a class suppose A and write methods inside it, now we want to use methods or variables of class A so instead of creating the same methods inside the new class we use methods and variables of class A, this is known as inheritance. Here class A is called parent class and class that uses Class A's properties is called the child class. In inheritance, child class objects acquire all the properties and behaviors of a parent class.

Polymorphism

Polymorphism means many forms. If a single task is performed in different ways, it is known as polymorphism. Polymorphism in Java is achieved by method signature and declarations. In Java, polymorphism is mainly two types: Overloading and Overriding.

Abstraction

Only essential details are displayed to the user and non-essential details are hidden to the user is known as abstraction. In other way hiding internal details and showing functionality is known as abstraction. For example a car, the user sees a car as a car rather than its individual components. In Java, Abstraction is achieved by abstract class and interface.

Encapsulation

Wrapping code and data together into a single unit are known as encapsulation. it is also known as data hiding. Here we are hiding our data and code inside a single class.

We will see these topics in detail in later chapters.



Other Posts You May Like
Please leave a comment below if you like this post or found some error, it will help me to improve my content.

Comments

Popular Posts from this Blog

Shell Script to find sum, product and average of given numbers - The Coding Shala

New Year Chaos Solution - The Coding Shala

Shell Script to Create a Simple Calculator - The Coding Shala

Java Method Overloading - The Coding Shala

Java Program to Convert Binary to Decimal - The Coding Shala