This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Functions

 
Amit Sethi
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q. Class contain Instance variable, class variable, methods, static methods. Are these simple methods, class method(only one time space is given to methods) or instance method(space is given for every object).



PLS help me.
regards
Amit
 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you give an example for what you call a"simple method"? your post is kind of hard to understand... :-)

cheers,
jan
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't say "class variable":-

static methods and variables:-
  • One copy in memory for each class
  • Called by myClass.myStaticMethod();
  • Every instance of that class has access to the same copy of the static method or variable
  • A static method does not have access to any instance variables, or instance methods, or the this and super keywords.

  • instance methods and variables:-
  • All methods and variables not called "static" are instance methods or variables. Is that what you mean by "simple methods?"
  • There is one copy of each instance variable in memory for each instance of the class, so there may be many of them.
  • You gain access to instance methods and variables by calling myObject.myMethod();
  • Each instance method has access to any static members of its class, but it is always the same static member.
  • All instance methods have access to all other instance methods and instance variables from their own object. This usually represents different data in different objects.
  • Instance methods have access to the this and super keywords.
  • Does that help at all?

    CR
    [ May 31, 2006: Message edited by: Campbell Ritchie ]
     
    Campbell Ritchie
    Sheriff
    Posts: 48652
    56
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    . . . And please think of titles for your threads which tell readers what they are about. "Functions" is too vague.
     
    Ryan McGuire
    Ranch Hand
    Posts: 1057
    4
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Amit Sethi:
    Q. Class contain Instance variable, class variable, methods, static methods. Are these simple methods, class method(only one time space is given to methods) or instance method(space is given for every object).


    I agree with what Campbell has said, but let me go back to one thing in the original question.

    Instance methods are not in memory multiple times. Even in the most complex multi-threaded application with huge number of objects, the executable code for the method is in memory just once.* Multiple threads might be executing the same methods simultaneously, but each one would be using the same executable code with (most likely) different variables/objects.

    Of course each object has its own memory space allocated for instance variables.


    * If I understand correctly, you could have an app that has multiple class loaders, in which case the code for a class's methods might be in memory more than once. In general, however, each class's code is loaded only once. (If I'm mistaken, someone please say so.)
    [ May 31, 2006: Message edited by: Ryan McGuire ]
     
    Amit Sethi
    Ranch Hand
    Posts: 45
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks a lot ...Jan,Campbell,Ryan

    What i got from ur answers is :

    simple methods are not given space for every object, they are given space only once like static methods but both are different by properties.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic