What does the line static SomeThing mThing mean? ? static is like a call to a class without using an object, but here it looks like a static object, but it probably can't be, what does this record mean?

class SomeThing implements Runnable { public void run() { System.out.println("Привет из побочного потока!"); } } public class Program { static SomeThing mThing; public static void main(String[] args) { mThing = new SomeThing(); Thread myThready = new Thread(mThing); myThready.start(); System.out.println("Главный поток завершён..."); } } 

An example of this article is https://habrahabr.ru/post/164487/

  • you and appeal to the field of class. and where there is a link from the class field indicates a tertiary question. - etki pm

1 answer 1

This is a static member of the class, the field in this case, it can be accessed by the name of the class without using objects.

  • but in the SomeThing class this mThing field is not declared and the SomeThing class is not static but normal? - mtb
  • @mtb, non-static classes can have static members. If you don't notice, then the main method is static. The field is declared static for an example, most likely in order to facilitate access to it from the main method, otherwise you would have to create an object. - DanielOlivo
  • @mtb you are confusing something ..... mThing is just the SomeThing type, and not that this field should be declared in that class ....... it's a crazy nonsense ...... ... This field is declared with this type just in the Program class ..... which means that ..... in the Program class there will be a static mThing field, such as SomeThing , which can be addressed at any time .. ... Program::mThing for example from another class ...... or just as mThing from a static method of the same class - Alexey Shimansky
  • @ Alexey Shimansky, for Program Java just for Program.mThing - DanielOlivo pm
  • yes it is really confused - after all, simply the declarations of the field of the class Program with the data type SomeThing - mtb