मराठी

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 - Computer Science (Theory)

Advertisements
Advertisements

प्रश्न

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?

  1. All objects of class Student share the same value of school_Name.
  2. The value of school_Name cannot be changed during program execution.
  3. The keywords static and final cannot be used together for a variable.

पर्याय

  • Only I and II

  • Only II and III

  • Only I and III

  • Only III

MCQ
Advertisements

उत्तर

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
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
2025-2026 (March) Official Board Paper
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×