在学生类中,此函数中使用的关键字指的是什么?它到底返回什么?它也仅在Java或C / C ++中使用吗?如果以任何其他语言使用,会有什么区别吗?
class Student
{
private String name;
private String section;
public static Comparator BY_NAME = new ByName();
public static Comparator BY_SECTION = new BySection();
public void setName(String name) {
this.name = name;
}
public void setSection(String section) {
this.section = section;
}
public String getName()
{
return this.name;
}
public String getSection()
{
return this.section;
}
private static class ByName implements Comparator
{
public int compare(Object s1, Object s2)
{
return ((Student)s1).name.compareTo(((Student)s2).name);
}
}
private static class BySection implements Comparator
{
public int compare(Object s1, Object s2)
{
return ((Student)s1).section.compareTo(((Student)s2).section);
}
}
}
在Java和c ++中,“ this”是指对象的变量,而不是类的变量。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句