I have the following block of code:
class Student{
int age; //instance variable
String name; //instance variable
public Student()
{
this.age = 0;
name = "Anonymous";
}
public Student(int Age, String Name)
{
this. age = Age;
setName(Name);
}
public void setName(String Name)
{
this.name = Name;
}
}
public class Main{
public static void main(String[] args) {
Student s; //local variable
s = new Student(23,"Jonh");
int noStudents = 1; //local variable
}
}
My question is related to what are local variables, instance variables in order to know where they are allocated, wether in HEAP or STACK memory. In the default constructor it seems to exist only one Local variable, which the one created by the 'this' keyword, but howcome ' name = "Anonymous";' is not considered to be a local variable? It's pf the Object type, but those can be local varibles too, correct? By the way can you give an example of an object created/instantiatedwith the default constructor? Thank you!