Inheritance and the “this” keyword

前端 未结 5 1728
有刺的猬
有刺的猬 2020-12-31 09:29

Suppose that we have next situation:

Parent class A:

class A{  
    public A(){}
    public doSomething(){  
        System.out.println(this.getCla         


        
5条回答
  •  情书的邮戳
    2020-12-31 10:11

    this doesn't do anything for you in this situtaion. Calling this.getClass() is no different than just calling getClass();

    So, A calls getClass(), which will return B if you are dealing with an instance of B that extends A.

提交回复
热议问题