Prashnikaप्रश्निका
Code
About
‹ Back to the paper

Question 1(vii)

1 mark

Computer ScienceISC 2026 Improvement Computer Science Paper 1MCQObjects

Choose the correct option.

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

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

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.