In Java, it is possible to type cast the 'this' keyword to refer to any of a given class's superclasses. However, trying to do the same with the 'super' keyword results in a syntax error. Why does it not work with the 'super' keyword?
In Java, it is possible to type cast the 'this' keyword to refer to any of a given class's superclasses. However, trying to do the same with the 'super' keyword results in a syntax error. Why does it not work with the 'super' keyword?
this has reference of object from which method or constructor is called.
super is used to refer parent class variables and methods. In short super keyword cannot be used for up casting.
You can create a method returnThis(){return this;} in parent class and call it in child class to get reference of parent class this for that particular object.
super is used to refer to the super class and doesn't represent any object. this keyword represents the current object from within the this has been called.
super is used in three places:
Please read more about super here