Question: . Consider the following class declaration in java. public class StudentInfo { private String major; public String getMajor() { return major; } // There may

. Consider the following class declaration in java. public class StudentInfo { private String major; public String getMajor() { return major; } // There may be fields, constructors, and methods that are not shown } The following instance variable and method appear in the client class. private StudentInfo[] students; /** @param major a string to be checked * @return the number of students that have the given major. */ public int enrollmentInMajor(String major) { int count = 0; for (int i=0; i < students.length; i++) { StudentInfo k = students[i]; if ( /* expression */ ) count++; } return count; } Which of the following could be used to replace /* expression */ so that enrollmentInMajor will compile without an error and the method will return the number of students that have the given major? a) major == students[k].getMajor() b) major == k.major c) major.equals(k.major) d) major.equals(getMajor(k)) e) major.equals(k.getMajor()) and can you please expalin why? I'm confused between equals and ==

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!