Introduction to Static Methods and Properties
Learn about static methods and properties, how to access them from within and outside classes, and some of their disadvantages.
In certain cases, we might want to approach the methods and properties of a class without the need to first create an object of that class. We can do this by defining the methods and properties of a class as static. Even though the use of static methods and properties is not considered good practice, there are certain cases where it may be particularly useful.
Note: We can access static methods and properties without the need to first create an object, but their use should be limited.
In the previous lessons, we learned about public
, protected
, and private
modifiers. Now, we’ll look at the static
modifier. Static modifiers allow access to class properties and methods without the need to create objects of that class.
Defining static methods and properties
Get hands-on with 1400+ tech skills courses.