Accessor Method for Private Data
Consider the following partial class declaration.
public class SomeClass
{
private int myA;
private int myB;
private int myC;
// Constructor(s) not shown
public int getA()
{ return myA; }
public void setB(int value)
{ myB = value; }
}
Which of the following changes to SomeClass will allow other classes to access, but not modify, the value of the myC instance variable?
A
Make myC public.
B
Include the method:
private int getC() { return myC; }
C
Include the method:
public void getC(int x) { x = myC; }
D
Include the method:
public int getC() { return myC; }
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | sailajavadlamani33 | 2 | 3 | 0m 00s | 190 |
| #2 | dinhhoa | 1 | 1 | 0m 00s | 100 |
| #3 | sgarv2513 | 1 | 1 | 0m 00s | 100 |
| #4 | Ishaan.m.kurup | 1 | 1 | 0m 00s | 100 |
| #5 | anvitakeni01 | 1 | 1 | 0m 00s | 100 |
| #6 | angelajxi11 | 0 | 1 | 0m 00s | -10 |
| #7 | songqiuhui2012 | 0 | 2 | 0m 14s | -34 |
| #8 | y.seong2027 | 1 | 1 | 4m 00s | -140 |
| #9 | suhanakochhar006 | 1 | 2 | 4m 30s | -180 |
| #10 | psak12 | 1 | 2 | 11h 39m | -41,881 |
APFIVE