Const keyword

  • Constants are one type of variable which we can define for any class with keyword const.
  • Value of these variables cannot be changed any how after assigning.
  • Class constants are different than normal variables, as we do not need $ to declare the class constants.
  • If we are inside the class then values of the constants can be get using self keyword, but accessing the value outside the class you have to use Scope Resolution Operator.

Example 1

Output:

Const keyword

Example 2

Output:

Const keyword
Next Topic




Contact US

Email:[email protected]

OOPs Const Keyword
10/30