Java Classes and Objects
🔹 Java Classes and Objects
Java is an object-oriented programming language, so classes and objects are the foundation of Java programs.
✅ 1. What is a Class?
A class is a blueprint or template that defines the attributes (variables) and behaviors (methods) of objects.
-
Class name starts with an uppercase letter by convention.
-
Attributes → Store object data.
-
Methods → Define actions the object can perform.
✅ 2. What is an Object?
An object is an instance of a class. It has its own copy of the class attributes and can use class methods.
📌 Output:
✅ 3. Object Syntax
-
newkeyword creates a new object in memory. -
Each object has its own copy of instance variables.
✅ 4. Multiple Objects Example
📌 Output:
✅ 5. Key Points
-
Class → Blueprint (defines properties and behaviors).
-
Object → Instance of a class (has its own state).
-
Attributes → Variables inside a class.
-
Methods → Functions inside a class.
-
newkeyword → Creates object in memory. -
Objects can have different values for the same attributes.
