How does java store objects in memory
In java memory to all objects are dynamically allocated. When we declare a new object of some Class Type it just creates a reference to object. To allocate memory in heap "new" operator is Used.
Class Test{
void addDetails()
{
System.out.println("abdjdbcbd");
}
public static void main(String a[])
{
Test t;
t.addDetails(); //runtime error not intialized
}
}
Class Test{
void addDetails()
{
System.out.println("abdjdbcbd");
}
public static void main(String a[])
{
Test t = new Test();
t.addDetails();
}
}
In java memory to all objects are dynamically allocated. When we declare a new object of some Class Type it just creates a reference to object. To allocate memory in heap "new" operator is Used.
Class Test{
void addDetails()
{
System.out.println("abdjdbcbd");
}
public static void main(String a[])
{
Test t;
t.addDetails(); //runtime error not intialized
}
}
Class Test{
void addDetails()
{
System.out.println("abdjdbcbd");
}
public static void main(String a[])
{
Test t = new Test();
t.addDetails();
}
}
No comments:
Post a Comment