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;
}
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();
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)