this: Cannot use this in static context

后端 未结 5 535
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-28 12:10

Can you please help me with below code. The error is: \"Cannot use This in a static context\"

public class Sample2 {
    /**
     * @param a         


        
5条回答
  •  有刺的猬
    2020-11-28 12:21

    See, "this" keyword refers to current object due to which method is under exceution. As, you cannot call static method using instance of class. That is why, "this" can't be used in the above example in a static method as it is trying to print current instance wich is not at all created. So, I think thats why there is an compile time error that you are getting.

提交回复
热议问题