14
Reply

Can we use “this” within a static method?

Pradeep Yadav

Pradeep Yadav

7y
3.5k
3
Reply

    no. this keyword denote instance.....and static method does not support instance

    No, this keyword denotes instance variables and functions. In static method, Only static properties initialize.

    No, this keyword refers current instance of the class. Static methods do not have instance/object. Hence we can not use this keyword. We call a static method using ClassName.StaticMethodName

    By static methods you can write:MyClass.static_method();

    Technically its not possible , because static portion execute before any other part of code o this keyword will be without referenced

    No, We can not use, we can only use static variables/methods in a static method.

    no

    Static method doesnt allow "this" keyword.

    Static method doesnt allow "this" keyword.

    No, this keyword refers current instance of the class. Static methods do not have instance/object. Hence we can not use this keyword.

    The answer is no because static method does not need any object to be called, and this keyword always point to a current object of a class. simply if there is no object then how the keyword point to any current object so,we cannot use this keyword here.

    No,This Keyword Refer to Current Insance only, and static method or properties are not belong to any particular instance ,static is common for all insances

    No

    No bcz we directly call method from class name.