exam questions

Exam 98-361 All Questions

View all questions & answers for the 98-361 exam

Exam 98-361 topic 1 question 11 discussion

Actual exam question from Microsoft's 98-361
Question #: 11
Topic #: 1
[All 98-361 Questions]

You are designing a class for an application. You need to restrict the availability of the member variable accessCount to the base class and to any classes that are derived from the base class.
Which access modifier should you use?

  • A. Internal
  • B. Protected
  • C. Private
  • D. Public
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Django
Highly Voted 3 years, 3 months ago
is this protected?
upvoted 18 times
Jose
2 years, 11 months ago
Assuming I've understood the question properly (English is not my native language) you are right. It has to be protected because a private variable could only be accesed in the class where it is declared.
upvoted 13 times
...
...
Boruc
Highly Voted 2 years, 1 month ago
Should be protected.
upvoted 16 times
...
Oryza
Most Recent 3 weeks, 3 days ago
I think this is a TRICKY question. Read carefully.. to "the" base class and to any classes that are derived from "the" base class. ..doesn't mean the one that we are designing is the base class, but our class is derived from certain base class along with another class that derived from that class to, so thats why it's a "private"
upvoted 1 times
...
Thooom
5 months, 2 weeks ago
Selected Answer: B
javascript:void(0)
upvoted 1 times
...
AishwaryaGupta
1 year ago
Answer is private becoz read the question carefully they wrote restricted .
upvoted 1 times
matt11
11 months, 2 weeks ago
to anyone reading this, please ignore this comment, it's not correct. Private members are not accessible in derived classes. You can test this really easily by creating a simple test C# console app with a base and derived class and seeing what you are able to access from the derived class: public class MyBaseClass { private bool _thePrivateField = true; protected bool _theProtectedField = true; } public class MyChildClass : MyBaseClass { public void TheMethod() { bool tryingToAccessThePrivateField = base._thePrivateField; bool tryingToAccessTheProtectedField = base._theProtectedField; } } If you do this you'll see a red squiggly line under 'base._thePrivateField' in 'MyMethod', because it's not accessible
upvoted 7 times
...
...
qweasdcde
1 year, 3 months ago
"to the base class and to ANY classes that are derived" It MUST be private
upvoted 1 times
...
SamarHussain
1 year, 8 months ago
private is accesible only within class. Protected is the answer
upvoted 4 times
...
Pomphard
1 year, 9 months ago
The answer should be protected: A protected member is accessible within its class and by derived class instances. https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/protected
upvoted 8 times
...
DamZ
1 year, 10 months ago
A private member ( i ) is only accessible within the same class as it is declared. A member with no access modifier ( j ) is only accessible within classes in the same package. A protected member ( k ) is accessible within all classes in the same package and within subclasses in other packages.
upvoted 2 times
Pomphard
1 year, 9 months ago
What you're thinking of is 'protected internal', which differs quite a lot from the default protected behaviour: A protected internal member is accessible from the current assembly or from types that are derived from the containing class. https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/protected-internal
upvoted 3 times
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago