OOPs Concepts in Java

Object-Oriented Programming System (OOPs) is a methodology to represent real-world entities into programming. Many programming languages follow OOPs principles, including C++, Java, PHP, C#, and Python. Java supports all OOPs principles except multiple inheritance.

Concepts of OOPs:

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

Class

Class defined as a blueprint for an object. We can create as many Objects for a class. It is often referred to as a template to create an object. Java allows a programmer to create your type using classes. In java String is not a primitive data-type it is class.
 

Object

An object defined as an instance of the class. The object was having two characteristics states (attributes) and behaviours
If you consider a dog is an object. The states or attributes of the dog are Breed, Age, and Color. Behaviours are Eat, Sleep, and Bark.
 

Inheritance

Inheritance means acquiring the properties and behaviours of another class. It is one of the key features of OOPs (Object Oriented Programming System). By using inheritance, we can reuse the attributes and methods from other classes (superclass).
 

Abstraction

Abstraction is the process of showing what is essential to the user and hiding all non-essential details. In java, we can implement the abstraction using Abstract classes and Interfaces.
 

Encapsulation

Encapsulation means binding the states (attribute) and behaviours (methods) in a single unit. Class is the best example of Encapsulation in java. In java, Encapsulation is achieved by making fields as private and providing access to them via public methods. Getter and Setter's methods used for this purpose.
 

Polymorphism

The dictionary meaning for the word "Poly" is many, and "morphs" means forms. In OOPs polymorphism means have many ways. Method overriding is the best example of polymorphism in java.

Post a Comment

0 Comments