Exforsys
+ Reply to Thread
Results 1 to 3 of 3

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......

  1. #1
    04bot23 is offline Junior Member Array
    Join Date
    Jun 2009
    Answers
    1

    data and methods

    Can any one please tell me
    How the data and methods are stored in any OOPs language?


    thanks in advance...


  2. #2
    sam_kv1 is offline Junior Member Array
    Join Date
    Jul 2009
    Answers
    2
    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.


  3. #3
    Sudheer Kethavarapu is offline Junior Member Array
    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



Latest Article

Network Security Risk Assessment and Measurement

Read More...