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
Include the method:
public int getC() { return myC; }
B
Include the method:
private int getC() { return myC; }
C
Make myC public.
D
Include the method:
public void getC(int x) { x = myC; }
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | sailajavadlamani33 | 2 | 3 | 0m 00s | 190 |
| #2 | anvitakeni01 | 1 | 1 | 0m 00s | 100 |
| #3 | Ishaan.m.kurup | 1 | 1 | 0m 00s | 100 |
| #4 | sgarv2513 | 1 | 1 | 0m 00s | 100 |
| #5 | dinhhoa | 1 | 1 | 0m 00s | 100 |
| #6 | bommasam000 | 1 | 1 | 0m 13s | 87 |
| #7 | chunxiangxu.cxu | 1 | 1 | 1m 34s | 6 |
| #8 | angelajxi11 | 0 | 1 | 0m 00s | -10 |
| #9 | songqiuhui2012 | 0 | 2 | 0m 14s | -34 |
| #10 | varunrajaram1 | 1 | 1 | 3m 05s | -85 |
Items per page:
10
1 – 10 of 14
APFIVE