I have the following code:
class Student{
int age;
String name;
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;
s = new Student(23,"Jonh");
int noStudents = 1;
}
}
My question is what are local variables, instance variables, in order to know where they are allocated in HEAP or STACK memory. In the default constructor, it seems that there is only one Local variable that the keyword 'this' creates, but howcome' name = "Anonymous"; not considered a local variable? This is an object type, but it can also be local variables, right? By the way, can you give an example of an object created / created using the default constructor? Thank!
source
share