Hello sivasayanth.
First, understand that:
- If we say that one object is an instance of a class then it means that the object has the same attributes and functionality as that class.
- Classes are usually expressed by making the first letter capital.
Try the following example:
Let's say we have a class called Animal. The class "Animal" has some attributes that gives it meaning and function. Now lets say that we have a "dog" and a "cat". Both are instances of the class "Animal". In Java it can be said:
Animal dog = new Animal("Ben", 3);
Animal cat = new Animal("Jacky", 2);
Now "dog" and "cat" are similar in the sense that the are both instances of Animal. Now lets define the "Animal" class. Lets say that an Animal has a name and an age. The Animal class could be defined:
class Animal{
// Attributes
private String name;
private int age;
// Behavior
public void grow(){
age++;
}
// Constructor
public Animal(name, age){
this.name = name;
this.age = age;
}
}
You do not have to understand the code yet, but try to see it as "blueprints" for an Animal.
Do you understand now?
