Home

Java Static Quiz 2

We want to know how many student objects are created so far. Fill in the blanks such that the variable count holds the number of Student objects have been created.

public class Student{
  private String name;
    int count;

  /**
  *   Constructor
  */
  public Student(String name) {
    this.name = name;
     ;
  }

  public static void main(String[] args){
    Student s1 = new Student("alice");
    assert(s1.count == 1);
    Student s2 = new Student("Bob");
    Student s3 = new Student("Cathy");
    assert(s3.count == 3)
  }
}
Blank 1:
Blank 2: