Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The getID method below is a member of the Person class. Which of the following i

ID: 3845939 • Letter: T

Question

The getID method below is a member of the Person class. Which of the following is true with respect to the getID method?
private int getID()
{
return ID;
}

1. The getID method cannot be accessed.

2. FalseThe getID method can only be accessed by code in the Person class.

3. The getID method can be accessed from the code of any class in the same folder that creates a Person object.

4. The getID method can be accessed from the code of any class that creates a Person object.

1. The getID method cannot be accessed.

2. FalseThe getID method can only be accessed by code in the Person class.

Explanation / Answer

1.   Method getID of Person class is an getter method that returns value of the variable ID.

2.   Access Specifier of this method is private:


Evaluating each of the following options:

Option 1: getID method can be accessed.

       So this statement is false
      
      
Option 2: As method getID is of private, it can only be accessed by members of Person class

        So this is true statement
      
      
Option 3: The getID method cannot be accessed from the code of any class in the same folder that creates a Person object (as the access specifier is private).

        So this statement is false
      
      
Option 4: The getID method cannot be accessed from the code of any class that creates a Person object (as the access specifier is not public).  

        So this statement is false
      

Hence correct option is (2)       

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote