
- Forum
- Programming Talk
- Java
- data and methods
data and methods
This is a discussion on data and methods within the Java forums, part of the Programming Talk category; Can any one please tell me How the data and methods are stored in any OOPs language? thanks in advance......
-
data and methods
Can any one please tell me
How the data and methods are stored in any OOPs language?
thanks in advance...
-
data and methods form an object...which are stored under a class.. so wen ya creatin a class, ya indirectly specifyin rather tellin d compiler wat type d objects must be.. in java the storage of objects are nt in stack but in heap.
-
05-19-2011, 08:07 AM #3
- Join Date
- May 2011
- Answers
- 5
A class can contain both data and methods.
when ever u create an instance to class i.e., object , the memory wil be allocated to both data(variable) and methods.
every time u create an object , a spreate memory is allocated to data(variables) of every object. but for methods, memory wil be allocated only once and that to when u create the very first object of the class.
Eg:
class Sample
{
int a,b;
void getdata();
void display();
}
//creating objects
Sample obj1; // memory allocates for variables a,b (of obj1) and methods getdata(), display()
Sample obj2; //a saparate memory allocates for variables a,b (of obj2).
Sample obj3: //a saparate memory allocates for variables a,b (of obj3).
ur's
sudheer
-
Sponsored Ads

Reply With Quote





