本文主要是介绍java样卷答案,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1 a
97
2 false true
false and true
3
4 5 10 15
5 10 20 50
注意逗号不要忘记了
6 10000
7 ia=11,ib=20
8 [John,Carl,Tom]
9 1000 100
10 1
1 2 3
下面拍自书上P72
11 abc123
abc123
abc
12 50
20
30
30
20
13
1
this.name=name;
this.waveLength=waveLength;
private Colors(String name,int waveLength)
{
this.name=name;
this.waveLength=waveLength;
}
2
注意不要死记下面这种形式,按照题目要求来
return getClass().getName()+”[name=”+name+”,waveLength=”+waveLength+”]”;
public String toString()
{
return "名称:"+name+",波长:"+waveLength;
}
3 蓝色
BLUE
4 蓝色
5 2
14
1
(参考老师PPT7.2.2里面的代码)
public int compare(Engineer E1,Engineer E2)
{
return (int) E1.salary-E2.salary;
}
2
老师PPT7.2.3原代码 super.clone()是调用的Obeject.clone()方法
Engineer cloned=(Engineer) super.clone(); //最开始还把Engineer写的employer,老师PPT上的
cloned.hireDay=(Date)hireDay.clone(); // hireDay的D忘记大写
return cloned;
3
if(this==otherObject) return true; //otherObject容易错写成otherObeject
if(otherObject==null) return false;
if(getClass()!=otherObject.getClass())
return false;
Engineer other=(Engineer) otherObject;
return name.equals(other.name)&&salary==other.salary&&hireDay.equals(other.hireDay);
4
return Objects.hash(name,salary,hireDay); //容易漏写s
5
super(name,salary,hireDay); //这里有些疑问hireDay写不写。应该是不写的,因为这相当于调用父类的构造函数,父类的构造函数确实只有这两个参数,所以这里也只能写两个,这也是为什么写三个就会报错。而且父类的构造函数里面有对hireDay的初始化。
this.speciality=speciality;
6
要先调用父类的equals
if(!super.equals(otherObject)) return false;
SeniorEngineer other=(SeniorEngineer)otherObject;
return speciality==other.speciality; //==写成了=
7
return Objects.hash(super.hashCode(),speciality); //Objects的s容易漏写
8 这块还没完全弄懂,campareTo不是Comparator的方法啊,这里的关键就是lamda表达式可以作为一个接口的对象,而不用再单独声明一个实现接口的类,所以它这里可以用Comparable接口中的compareTo方法,虽然这个所在的类只实现了Comparator接口,理解了这个是很关键的,所以老师出的这个题是出得很妙的。
Arrays.sort(engineers,(E1,E2)->E1.getName().compareTo(E2.getName()));
15
java声明一个Int型变量怎么声明的?
数组长度可以由t.length得到
T[] t1;
int i;j;
for(i=0;i<t.length;i++)
{
t1(t.length-1-i)=t(i);
}
t=t1;
==========================================================
1 97
2 false and true
3 student6 has passed the quiz:true
student10 has passed the quiz:false
4 5 10 15
5 10,20,50,
6 10000
7 ia=11,ib=20
8 [John,Carl,Tom]
9 1000 100
10 1 2 3
11 abc123
abc
12 50
20
30
13
1
private Colors(String name,int waveLength)
{
this.name=name;
this.waveLength=waveLength;
}
2
public String toString()
{
return "名称:"+name+",波长:"+waveLength;
}
3 BLUE
4 蓝色
5 2
14
1
public int compare(Engineer E1,Engineer E2)
{
return (int) E1.salary-E2.salary;
}
2
Engineer cloned=(Engineer) super.clone();
cloned.hireDay=(Date)hireDay.clone();
return cloned;
3
if(this==otherObject) return true;
if(otherObject==null) return false;
if(getClass()!=otherObject.getClass())
return false;
Engineer other=(Engineer) otherObject;
return name.equals(other.name)&&salary==other.salary&&hireDay.equals(other.hireDay);
4
return Objects.hash(name,salary,hireDay);
5
this.speciality=speciality;
6
if(!super.equals(otherObject)) return false;
SeniorEngineer other=(SeniorEngineer)otherObject;
return speciality==other.speciality;
7
return Objects.hash(super.hashCode(),speciality);
8
Arrays.sort(engineers,(E1,E2)->E1.getName().compareTo(E2.getName()));
这篇关于java样卷答案的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!