PRASHNIKAप्रश्निका
Back to the paper

Consider the following code segment: class Student { static int totalStu = 0; String name; public…

Computer Science20261 markMCQ
Consider the following code segment:
class Student
{
    static int totalStu = 0;
    String name;
    public Student(String n)
    {
        name = n;
        totalStu++;
    }
}
Identify the valid statement(s)? I. The variable totalStu keeps count of all Student objects created II. Each object of the class gets its own copy of totalStu III. The variable totalStu can be accessed using Student.totalStu
  • (a)Only I and II
  • (b)Only I and III
  • (c)Only II and III
  • (d)Only III

Answer

Answer

AI

Correct option: (b)

Answer: (b) Only I and III I is true: totalStu is incremented inside the constructor every time a Student object is created, so it keeps count of all objects created. II is false: totalStu is declared static, so it is shared by all objects of the class — there is only one copy, not a separate copy per object. III is true: a static member can be accessed directly through the class name, i.e. Student.totalStu.
Objects

From ISC 2026 Improvement Computer Science Paper 1, question 1(vii).