在类Student这里函数中使用的关键字是指什么? 它到底是什么回报? 它只用于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);
}
}
}
答案 0 :(得分:0)
在Java和c ++中,“this”指的是对象的变量而不是类的变量。