Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6826923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:12:19+00:00 2026-05-26T22:12:19+00:00

While thinking a little bit about programming in Java/C# I wondered about how methods

  • 0

While thinking a little bit about programming in Java/C# I wondered about how methods which belong to objects are represented in memory and how this fact does concern multi threading.

  1. Is a method instantiated for each object in memory seperately or do
    all objects of the same type share one instance of the method?
  2. If the latter, how does the executing thread know which object’s
    attributes to use?
  3. Is it possible to modify the code of a method in
    C# with reflection for one, and only one object of many objects of
    the same type?
  4. Is a static method which does not use class attributes always thread safe?

I tried to make up my mind about these questions, but I’m very unsure about their answers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:12:20+00:00Added an answer on May 26, 2026 at 10:12 pm

    Each method in your source code (in Java, C#, C++, Pascal, I think every OO and procedural language…) has only one copy in binaries and in memory.

    Multiple instances of one object have separate fields but all share the same method code. Technically there is a procedure that takes a hidden this parameter to provide an illusion of executing a method on an object. In reality you are calling a procedure and passing structure (a bag of fields) to it along with other parameters. Here is a simple Java object and more-or-less equivalent pseudo-C code:

    class Foo {
      private int x;
    
      int mulBy(int y) {
        return x * y
      }
    }
    
    Foo foo = new Foo()
    foo.mulBy(3)
    

    is translated to this pseude-C code (the encapsulation is forced by the compiler and runtime/VM):

    struct Foo {
        int x = 0;
    }
    
    int Foo_mulBy(Foo *this, int y) {
        return this->x * y;
    }
    
    Foo* foo = new Foo();
    Foo_mulBy(foo, 3)
    

    You have to draw a difference between code and local variables and parameters it operates on (the data). Data is stored on call stack, local to each thread. Code can be executed by multiple threads, each thread has its own copy of instruction pointer (place in the method it currently executes). Also because this is a parameter, it is thread-local, so each thread can operate on a different object concurrently, even though it runs the same code.

    That being said you cannot modify a method of only one instance because the method code is shared among all instances.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While thinking about this question and conversing with the participants, the idea came up
I've been thinking about this problem for a while and have yet to come
I've been thinking about this object oriented design question for a while now and
Here's a little problem I've been thinking about for a while now that I
A while back, I learned a little bit about big O notation and the
EDIT 2009-Nov-04 OK, so it's been a little while since I first posted this
A while ago we started developing a new project which internally has about 25-30
I am a tinkerer—no doubt about that. For this reason (and very little beyond
I asked a little while ago a question about rollback, I have a new
I know a little bit about Object Oriented design , but I'm not sure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.