Java Classes And Instance
01. What is Class ?
Think of a Class as a blueprint, template, or a recipe. It is not a real thing yet; it just describes what something should look like and do.
As shown in the first image, a class is like a 3-compartment box that holds three things:
Name: What the class is called (e.g.,
Student,Car,Circle).Variables (Attributes): The data or information about it (e.g., a student has a
nameand agpa).Methods (Behaviors): What it can do (e.g., a student can
getName()orsetGpa()).
02.What is an Instance (Object)?
An Instance (also called an Object) is the real thing created using that blueprint. Look at the second image:
The blueprint is
Student.From that one blueprint, we created two real students: paul and peter.
They both have the same structure (
nameandgpa), but their actual information is different (Paul's GPA is 3.5, while Peter's GPA is 3.9).



Comments
Post a Comment