Ask Question
7 January, 23:41

Define the missing method. use "this" to distinguish the local member from the parameter name.

+3
Answers (1)
  1. 8 January, 03:31
    0
    Java Code

    class Students{

    private String name;

    private String rollNumber;

    public void setNameAndRollNumber (String name, String rollNumber) {

    this. name = name;

    this. rollNumber = rollNumber;

    }

    }

    Code Explanation

    In setNameAndRollNumber method there are two type variables, one is member variables which are associated with class and the second one are method parameters which are being past from external class.

    If we have both variables name similar to member variables then to distinguish between member variable and parameter, we need to add "this" before member variable to let compiler know that with "this" annotation we are changing value of member variable not parameters variable.

    If we don't use "this" with variable name then the compiler will give preference to parameters variable.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Define the missing method. use "this" to distinguish the local member from the parameter name. ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers