Ask Question
14 October, 09:45

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

+5
Answers (1)
  1. 14 October, 10:04
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers