Instance methods and thread-safety of instance variables

前端 未结 6 795
Happy的楠姐
Happy的楠姐 2021-01-30 23:40

I would like to known if each instance of a class has its own copy of the methods in that class?

Lets say, I have following class MyClass:

p         


        
6条回答
  •  轮回少年
    2021-01-30 23:44

    There are many situations in which an instance may be accessible from multiple classes. For example, if your instance is a static variable in another class, then all threads would share that instance, and you can get into big trouble that way. That's just the first way that pops into my mind...

提交回复
热议问题