GeekInterview.com
Series: Subject: Topic:
Question: 22 of 38

How is memory allocated by new ?
a) In a heap b) in a stack b) both a & b c) None of these.

Asked by: Interview Candidate | Asked on: Jul 12th, 2006
Showing Answers 1 - 22 of 22 Answers
lavanyachagantipati

Answered On : Jul 13th, 2006

sir ,please tell me wt exactly this new will do

Yes  1 User has rated as useful.
  
Login to rate this answer.
bharath kumar

Answered On : Jul 14th, 2006

ans:a)heap

Yes  2 Users have rated as useful.
  
Login to rate this answer.
bharath kumar

Answered On : Jul 14th, 2006

 new is a keyword that creates the instance of the class

  
Login to rate this answer.
pratap

Answered On : Jul 21st, 2006

java object create in heap but stored in stack

  
Login to rate this answer.
manna bhai

Answered On : Aug 2nd, 2006

   if u have instance variables in class so memory for all instance variable will be allocated in heap. not in stack stack is for method variable

  
Login to rate this answer.
siva kumar reddy

Answered On : Aug 9th, 2006

hi,

actually static variables ,local variables ,method parameters are stored in stack.somany stacks are created(one stack per one thread)

instance variables and java objects are stored in heap.only heap is created.

cheers

siva

  
Login to rate this answer.
k.r

Answered On : Aug 12th, 2006

The JVM allocates memory in two ways1) Stack: for local variables (declared in methods and constructors). this is deallocated once the method exits.2) heap: everytime an object is created using new keyword, it is allocated in the heap. theses have a longer lifespan. it the JVM runs out of space in the heap it gives a Java out-of-memory error.

Yes  1 User has rated as useful.
  
Login to rate this answer.
janmejay

Answered On : Aug 16th, 2006

Hey!NO NO........everytime an object is created using new keyword, it is allocated in the heap. these have a longer lifespan. if the JVM runs out of space in the heap it gives a Java out-of-memory error........................and local variables and methods goes to stack...and this is deallocated once the method exits and variables goes out of scope......

  
Login to rate this answer.
durga prasad reddy

Answered On : Aug 19th, 2006

stored in heap and the reference variables are stored in stack.if heap is filled then out of memory exception occurs

  
Login to rate this answer.
C.R.Venkatesh

Answered On : Aug 27th, 2006

Here is my 2 cents worth.



(a) Simply put, all Java Objects are allocated memory in Heap.




(b) Primitives types (not *array* of primitives) and references to objects are allocated on the stack.




(c) Importantly, each thread in the JVM gets it own stack and the VM option




-Xss decides the stack size for each thread.




Note: If the stack size is too small, eventually you see "StackOverflowError".


Example:class FooBar{    
public void get(MyTest obj)   // obj a reference to an object - stack.   
{          
int x = 10;    // Stack         
Vector tmpObj=new Vector(); // Heap         
...         
...   
}
}
 
Note:  tmpObj will be garbage collection based on the rules 
(like reference count and others) that GC maintains to check its life span.
HTH.

Yes  1 User has rated as useful.
  
Login to rate this answer.
Kishor raja Kumar

Answered On : Sep 25th, 2006

Hai All,

By using new operator we can allocate memory.ex:new A(); this statement

allocates memory for the class A. suupose A obj;means one reference will be create for the class A.When u write obj=new A(); then only that reference become object.for reference memory will not created.For objects only memeory will be created...

If i am wrong plz let me know

Thanks and Regards

kishor.V

  
Login to rate this answer.
zakir hussain

Answered On : Oct 14th, 2006

when memory is allocated in heap, it gets storage in heap.

  
Login to rate this answer.
gokul

Answered On : Nov 30th, 2006

when a jvm encounter the new keyword then it will try create object in heap only. But String is created in String pool which is one part of the heap.

  
Login to rate this answer.
ramesh chandra

Answered On : Jan 2nd, 2007

hi

u asked what actually new does

it creates memory for the variables just nothing but an constructor

it is operator which is used to allocate memory in c++  as per my knowledge is concerned

  
Login to rate this answer.
premanand_1984

Answered On : Jan 16th, 2007

View all answers by premanand_1984

ans is a] memory is allocate in heap..

  
Login to rate this answer.
Sony V George

Answered On : Apr 4th, 2007

a. ofcource the object will create on heap. When ever it will have live thread then only it will be on stack

  
Login to rate this answer.
sampra

Answered On : Mar 10th, 2008

View all answers by sampra

By the new operator memory always will be create in the heap

  
Login to rate this answer.
sampra

Answered On : Mar 10th, 2008

View all answers by sampra

in heap

  
Login to rate this answer.

By creating object to an class by using  "new" keyword shows that JVM allocates memory in heap area.   

  
Login to rate this answer.
Arun Ruhela

Answered On : Jul 3rd, 2012

Always object allocated memory in heap and method always memory allocated in stack.

  
Login to rate this answer.
malik_malik

Answered On : Sep 23rd, 2012

View all answers by malik_malik

When you declare a variable with new keyword its allocated space in heap.because we dynamically create a variable and we create a variable dynamically its allocated space in heap.

  
Login to rate this answer.
venkat

Answered On : Mar 7th, 2013

a) In a Heap

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Ads

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.