Advertisements
Advertisements
Question
Consider the following statement written in class Student where school_Name is its data member.
static final String school_Name = "Co-Ed School";
Which of the following statements are valid for school_Name?
- All objects of class Student share the same value of school_Name.
- The value of school_Name cannot be changed during program execution.
- The keywords static and final cannot be used together for a variable.
Options
Only I and II
Only II and III
Only I and III
Only III
MCQ
Advertisements
Solution
Only I and II
Explanation:
Here is the breakdown of why those lines are correct for the Java statement static final String school_Name = "Co-Ed School";:
- Line I is Correct (
static): Because the variable is static, it is stored in the class memory rather than inside each individual object. This means every "Student" object shares this exact same school name. - Line II is Correct (
final): Because the variable is final, it acts as a constant. Once it is set to "Co-Ed School", the program will not allow you to change it to something else later. - Line III is Incorrect: It is a standard practice in Java to use static and final together to create constants. There is no rule preventing them from being used on the same variable.
shaalaa.com
Is there an error in this question or solution?
2025-2026 (March) Official Board Paper
