Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
medium Solved by 13 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 int getC() { return myC; }

D

Include the method:
public void getC(int x) { x = myC; }

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question
Mark for review

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Total Time
Score
#1sailajavadlamani3323 0m 00s 190
#2anvitakeni0111 0m 00s 100
#3Ishaan.m.kurup11 0m 00s 100
#4sgarv251311 0m 00s 100
#5dinhhoa11 0m 00s 100
#6bommasam00011 0m 13s 87
#7chunxiangxu.cxu11 1m 34s 6
#8angelajxi1101 0m 00s -10
#9songqiuhui201202 0m 14s -34
#10varunrajaram111 3m 05s -85
Items per page:
10
1 – 10 of 14
No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|FAQ