Which Java access modifier allows visibility only within the same class?
Difficulty: Easy
About this MCQ
This Easy Programming Concepts question asks: Which Java access modifier allows visibility only within the same class? The correct choice is B. private. Read the options below, commit to one, then use the explanation to see why that choice holds and why the others do not.
Programming Concepts items like this one are written for Pakistan exams such as CSS, FPSC, PPSC, and NTS. The difficulty label is a hint about how much of the topic the stem assumes, not a score. Tags and exam names, when they are present, tell you where else the same idea is tested. Previous and next links stay in Programming Concepts so you can continue the subject. Related questions point at nearby stems if you want another angle on the same idea.
Treat the explanation as part of the question, not a footnote. If you missed it, reread the stem against the correct option before you open the next Programming Concepts item. A timed quiz is the same pool with a clock and a score. A past paper is a full sitting rather than this single question.
- A. public
Why not A: “public” does not fit this question. The answer is private.
- B. private ✓
- C. protected
Why not C: “protected” does not fit this question. The answer is private.
- D. default
Why not D: “default” does not fit this question. The answer is private.
Correct answer
B. private
Explanation
private is the term that matches “Which Java access modifier allows visibility only within the same class” (option B). Option A (public) does not fit this question. Option C (protected) does not fit this question. Option D (default) does not fit this question. For this Programming Concepts question, the accepted answer is private.
Source: Java Language Specification
Tags: java, oop, access modifiers
Submitted by: MCQsHub Editorial
Related MCQs
- What does Variable refer to?
- What is the name for a programming construct that repeats a block of code while a condition is true?
- Which of the following best describes Loop?
- Identify the correct concept described as: a reusable block of code that performs a specific task and can be c...
- Function is best defined as which of the following?
- A technique where a function calls itself to solve smaller instances of a problem. What is this concept called...