1) Is there memory required for methods, and when v create object, each object is going to have there own methods or for one class there will be one method all object will refer that.
Methods are the engines to process a data. they are simply some lines of code in your java class to modify the variables. the state of an object is its instance variables. so, when you create instance variables, then some memory will be allocated.
Methods and local variables are stored in stack, Object and instance variables are stored in heap.
The Main method is a method which will start the java application and it will be invoked by JVM.Once the program starts with the main method,the main method will be pushed in to the stack memory ,whatever method you are calling from main method will be pushed in to the stack at the top of the main. When the mothod copletes it will be popped up from the stack and it goes till the main get popped off.
please let me know if you have any doubts on that .
thank you Rajan for your reply,I have still doubt please don't mind. for example class Emp{ int empId; void getEmp(){ //body } } if we create 10 object for above class then each object have different value of instance variable of empId,what abt all object have same getEmp() method or each object have there own method, if all objects refers same method, then how its going to proceed with each instance variable.
class Emp{ int empId; void getEmp(){ //body } } if we create 10 object for above class then each object have different value of instance variable of empId,what abt all object have same getEmp() method or each object have there own method, if all objects refers same method, then how its going to proceed with each instance variable.
As you said each object will have its own instance variable inside object in heap, when it comes to methods which will store in the stack when you call a method from one object which will get expires once method completes same way happens for all the objects. Hope this clears you.
Please let me know if you have any doubts on this.