DEV Community

Kesavarthini
Kesavarthini

Posted on

Java Basics: Understanding Class and Object for Beginners

Hello everyone πŸ‘‹
This is my Day 2 learning blog on Java programming.
As a beginner, I’m sharing what I learned about Class and Object in a simple and easy-to-understand way.

If you are new to Java, this blog will help you understand the foundation of Java and OOP.

πŸ”Ή What is a Class in Java?

A class is a blueprint or template used to create objects.
β€’ It defines properties (variables) and behaviors (methods)
β€’ A class does not occupy memory until an object is created

Example:

class Student {
    int id;
    String name;
}
Enter fullscreen mode Exit fullscreen mode

Here, Student is a class with two variables: id and name.

πŸ”Ή What is an Object in Java?

An object is an instance of a class.
β€’ Objects represent real-world entities
β€’ Memory is allocated when an object is created
β€’ Objects are created using the new keyword

Example:

Student s1 = new Student();
Enter fullscreen mode Exit fullscreen mode

Here, s1 is an object of the Student class.

πŸ”Ή Real-World Analogy
β€’ Class β†’ Blueprint of a house
β€’ Object β†’ Actual house built from the blueprint

You can create many objects from one class.

πŸ”Ή Conclusion

Understanding Class and Object is the foundation of Java and OOP.
Once this concept is clear, learning advanced Java topics becomes much easier.

This is what I learned on Day 2 of Java, and I’ll continue sharing my journey. πŸš€

Top comments (0)