Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given the following Student class, which XXX is the correct syntax for overriding the compareTo ( ) method to compare the details of two students?

Given the following Student class, which XXX is the correct syntax for overriding the compareTo() method to compare the details of two students?
public class Student implements Comparable {
private String name;
private Integer grade;
Student(String name, Integer grade){
this.name = name;
this.grade = grade;
}
@Override
public int compareTo(Student tempStud){
int comparisonVal;
XXX
return comparisonVal;
}
}
a.
comparisonVal =(this.grade == tempStud.grade);
if (comparisonVal ==0){
comparisonVal =(this.name == tempStud.name);
}
b.
comparisonVal = grade.compareTo(name);
if (comparisonVal ==0){
comparisonVal = name.compareTo(grade);
}
c.
comparisonVal = grade.compareTo(tempStud.grade);
if (comparisonVal ==0){
comparisonVal = name.compareTo(tempStud.name);
}
d.
comparisonVal = tempStud.grade.compareTo(tempStud.grade);
if (comparisonVal ==0){
comparisonVal = tempStud.name.compareTo(tempStud.name);
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions

Question

State the importance of control

Answered: 1 week ago

Question

What are the functions of top management?

Answered: 1 week ago

Question

Bring out the limitations of planning.

Answered: 1 week ago

Question

Why should a business be socially responsible?

Answered: 1 week ago