Basic Java Knowledge.
Published: 2022-10-05 23:29:03

Even the **king of Java** had to read to understand what **OOP** really means.

As the name suggests, > Object-Oriented Programming
 or OOPs refers to languages that use objects in programming, they use objects as a primary source to implement what is to happen in the code. Objects are seen by the viewer or user, performing tasks assigned by you. Object-oriented programming aims to implement real-world entities like inheritance, hiding, polymorphism etc. in programming. The main aim of OOP is to bind together the data and the functions that operate on them so that no other part of the code can access this data except that function. I believe you understand how to declare a method in Java and have a full understanding of the types of methods that Java has.

For example, a dog is an object because it has states like colour, name, breed, etc. as well as behaviours like wagging the tail, barking, eating, etc.

**Concepts of Object Oriented Programming**

1. **Class**: The collection of objects is called class. It is a logical entity. A class can also be defined as a blueprint from which you can create an individual object. “Class doesn’t consume any space”.

```
public class Practice {

}
```

2. **Inheritance**: When one object acquires all the properties and behaviours of a parent object, it is known as inheritance. It provides code reusability. It is used to achieve runtime polymorphism. For example, Nigeria is a Parent Object; Lagos, Imo and Ogun states are all inheriting from the parent object.

3. **Polymorphism**: If one task is performed in different ways, it is known as polymorphism. In Java, we use method overloading and method overriding to achieve polymorphism.

```
public class Animal {
     
    private String name;
    
    private String color;

    private int age;
    
    public Animal(String name, String color, int age){
       this.name = name;
       this.color = color;
       this.age = age;
    }

    public Animal(String name, int age){
       this.name = name;
       this.age = age;
    }

```

4. **Abstraction**: Hiding internal details and showing functionality is known as abstraction. In Java, we use abstract class and interface to achieve abstraction.

```
public abstract class Animal {
    
   private Heart heart;

   private Lungs lungs;

   private Kidney kidney;

```

5. **Encapsulation**: Binding (or wrapping) code and data together into a single unit are known as encapsulation. For example, a capsule is wrapped with different medicines. A java class is an example of encapsulation. Java bean is the fully encapsulated class because all the data members are private here.

6. **Coupling**: Coupling refers to the knowledge or information or dependency of another class. It arises when classes are aware of each other. If a class has the details information of another class, there is strong coupling. In Java, we use private, protected, and public modifiers to display the visibility level of a class, method, and field. You can use interfaces for the weaker coupling because there is no concrete implementation.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tg5uhzl5ayzm0vx1ldgs.jpeg)

You can also view my medium account [here](https://medium.com/@okoroaforkelechi123)

Thank you for reading and I hope you learned something. **zip it now!**