Class is the blueprint for creating objects.
It is a set of objects with similar characteristics and behavior
Characteristics are implemented through member variables.
and behavior is implemented through member functionx.
A class is just the logic; inorder to use it : we need objects.
class employee{
name;
salary;
set Name(N){
name = N;
}
setSalary(S){
salary = S;
}
getSalary(){
return salary;
}
}
//The above is the blueprint
// to use the class
main(){
Employee objectName = new Emoployee();
objectName.setName("Raj");
objectName.setSalary(10000);
//We can use another object for another instance
Employee objectName2 = new Employee();
objectName.setName2("Ram");
objectName.setSalary(2000);
print(objectName.getSalary(); // prints : 1000
print(objectName2.getSalary();// prints : 2000
}
// This creates an instance of the class.
2 types of memory:
1. Stack : runtime , size is limited
2. Heap. : system. , size is large
In the heap mamory : we are storing the instance…
If the stack memory referencing it is no more there. : after a certain interval: internal garbage collector will work .
**Employee obj1 =** new Employee()
Stack Pointed by Heap