function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sourav PSourav P 

'THIS' keyword usage in a static variable inside a constructor

Hi, As per my understanding , the THIS keyword can be used only in an instance variable or method call inside a constructor. But may i know plz why in the below code, its been used for a static variable call inside a constructor ? Is that lega to call for static as well ? 

User-added image
Shyamala LokreShyamala Lokre
Static variables can be used inside a non static method including constructors. DEFAULT_STRING is a static variable which is used inside the default constructor. In this code 'this(string)' , which is the parameterized constructor, is called inside the default constructor. The string passed to this() could be anything includeing static variables.

I hope this helps.