How are this and super used

This is used to refer to the current object instance. super is used to refer to the variablesand methods of the superclass of the current object instance.

Showing Answers 1 - 1 of 1 Answers

Super() refers to the superclass of the class where the super keyword is currently being used.It is used to call the constructor of the superclass in the base class.
eg:
public class Class1{
public Class1(String arg){
super(arg);
}

This() is used for pointing the current class instance. It can be used with variables or methods.
eg:
void getValue()
{
this();

}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions