| preferred AP College board partner for AP classes
easy Solved by 16 students
Accessor Method for Private Data
< Prev
Next >

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; }

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1sailajavadlamani3323 0m 00s 190
#2dinhhoa11 0m 00s 100
#3sgarv251311 0m 00s 100
#4Ishaan.m.kurup11 0m 00s 100
#5anvitakeni0111 0m 00s 100
#6angelajxi1101 0m 00s -10
#7songqiuhui201202 0m 14s -34
#8y.seong202711 4m 00s -140
#9suhanakochhar00612 4m 30s -180
#10psak1212 11h 39m -41,881
APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy