Java OOPS - Introduction & Classes and Objects

Java OOPS - Introduction & Classes and Objects

Hi all, Welcome to the Object Oriented Programming(OOPs) series in Java.
In this series, we will cover all the concepts in OOPS. The order in which we will cover topics will be:-

  1. Classes and Objects (covered in this article)
  2. Data Hiding and Abstraction
  3. Encapsulation
  4. Inheritance
  5. Polymorphism
    a. Method Signature
    b. Method Overloading ( Compile-time polymorphism)
    c. Method Overriding ( Runtime polymorphism)

Java Classes and Objects

As we know Java is an OOP language, everything in java is associated with classes and objects.
Most of you might already be aware of what classes and objects are in Java. So without getting deep into it let us get a quick overview of each.

Objects in Java

If we look around us we can find many objects like cars, dogs, etc.
If we see a dog, it has attributes like color, breed, name, and behaviors like- barking, running, etc.
Similarly, software objects have attributes and behaviors. Software Object attributes are stored in variables and behaviors in methods.
We will see how to create objects in java after looking into classes

Classes in Java

Class is a blueprint or prototype of a real-world object.
Using classes we can create objects. It represents the set of properties or methods that are common to all objects of one type.

class Dog{
    //attributes -> variables
    String breed;
    String name;
    String color;

    public Dog(String breed, String name, String color) {
        this.breed = breed;
        this.name = name;
        this.color = color;
    }
    //behaviors -> methods
    void barking() {
    }
    void running() {
    }
}

We have created a Dog class it has different attributes(variables) breed, color, name, and behaviors(method) barking and running.

Once we create a class that is not enough because the class is just a blueprint, we need to create an object of the class to actually use it.

To create an object we need to use the 'new' keyword.

Dog d = new Dog("Bulldog","Mike","Brown");

This is it for this short article.
In the next one, we will start with Data hiding and Abstraction.
Thanks for Reading.
If any suggestions comment below.