public static void main(String[] args) {
FatherClass fc = new FatherClass();
ChildClass cc = new ChildClass();
}
}
A.FatherClass Create
FatherClass Create
ChildClass CreateB.FatherClass Create
ChildClass Create
FatherClass CreateC.ChildClass Create
ChildClass Create
FatherClass CreateD.ChildClass Create
FatherClass Create
FatherClass Create
7.请看如下代码
class Person {
private int a;
public int change(int m){return m;}
}
public class Teacher extends Person{
public int b;
public static void main(String arg[]){
Person p = new Person();
Teacher t = new Teacher();
int i;
// point x
}
}
下面哪些放在// point x行是正确的? A.i = b;
B.i = p.a;
C.i = p.change(30);
D.i = t.b;
8.下列选项中放置于“《插入代码》”处会编译出错的是
interface IFace{}
class CFace implements IFace{}
class Base{}
public class ObRef extends Base{
public static void main(String argv[]){
ObRef ob = new ObRef();
Base b = new Base();
Object o1 = new Object();
IFace o2 = new CFace();
《插入代码》
}
}
A.o1=o2;
B.b=ob;
C.ob=b;
D.o1=b;
9.已知类Student的定义如下:
public class Student {
String name;
Student(String name) {
this.name = name;
}
《插入代码》
}
main方法代码:
Student stu1=new Student(new String(“tom”));
Student stu2=new Student(“tom”);
System.out.print(stu1==stu2);
System.out.println(stu1.equals(stu2));
如果控制台的输出结果是false true,那么《插入代码》处填入的代码正确的是:
A.public boolean equals(Object obj) {
if (obj instanceof Student) {
Student stu = (Student) obj;
return stu.name==this.name;
} else {
return false;
}
}
B.public boolean equals(Object obj) {
if (obj instanceof Student) {
Student stu = (Student) obj;
return stu.name.equals(this.name);
} else {
return false;
}
}
C.public boolean equals(Object obj) {
if (obj instanceof Student) {
return obj.name.equals(this.name);
} else {
return false;
}
}
D.public boolean equals(Object obj) {
if (obj instanceof Student) {
return obj.name==this.name;
} else {
return false;
}
}10.指出下列程序运行的结果
public class Example{
String str=new String("good");
char[]ch={'a','b','c'};
public static void main(String args[]){
Example ex=new Example();
ex.change(ex.str,ex.ch);
System.out.print(ex.str+" and ");
System.out.print(ex.ch);
}
public void change(String str,char ch[]){
str="test ok";
ch[0]='g';
}
}
A.good and abc
B.good and gbc
C.test ok and abc
D.test ok and gbc
FatherClass fc = new FatherClass();
ChildClass cc = new ChildClass();
}
}
A.FatherClass Create
FatherClass Create
ChildClass CreateB.FatherClass Create
ChildClass Create
FatherClass CreateC.ChildClass Create
ChildClass Create
FatherClass CreateD.ChildClass Create
FatherClass Create
FatherClass Create
7.请看如下代码
class Person {
private int a;
public int change(int m){return m;}
}
public class Teacher extends Person{
public int b;
public static void main(String arg[]){
Person p = new Person();
Teacher t = new Teacher();
int i;
// point x
}
}
下面哪些放在// point x行是正确的? A.i = b;
B.i = p.a;
C.i = p.change(30);
D.i = t.b;
8.下列选项中放置于“《插入代码》”处会编译出错的是
interface IFace{}
class CFace implements IFace{}
class Base{}
public class ObRef extends Base{
public static void main(String argv[]){
ObRef ob = new ObRef();
Base b = new Base();
Object o1 = new Object();
IFace o2 = new CFace();
《插入代码》
}
}
A.o1=o2;
B.b=ob;
C.ob=b;
D.o1=b;
9.已知类Student的定义如下:
public class Student {
String name;
Student(String name) {
this.name = name;
}
《插入代码》
}
main方法代码:
Student stu1=new Student(new String(“tom”));
Student stu2=new Student(“tom”);
System.out.print(stu1==stu2);
System.out.println(stu1.equals(stu2));
如果控制台的输出结果是false true,那么《插入代码》处填入的代码正确的是:
A.public boolean equals(Object obj) {
if (obj instanceof Student) {
Student stu = (Student) obj;
return stu.name==this.name;
} else {
return false;
}
}
B.public boolean equals(Object obj) {
if (obj instanceof Student) {
Student stu = (Student) obj;
return stu.name.equals(this.name);
} else {
return false;
}
}
C.public boolean equals(Object obj) {
if (obj instanceof Student) {
return obj.name.equals(this.name);
} else {
return false;
}
}
D.public boolean equals(Object obj) {
if (obj instanceof Student) {
return obj.name==this.name;
} else {
return false;
}
}10.指出下列程序运行的结果
public class Example{
String str=new String("good");
char[]ch={'a','b','c'};
public static void main(String args[]){
Example ex=new Example();
ex.change(ex.str,ex.ch);
System.out.print(ex.str+" and ");
System.out.print(ex.ch);
}
public void change(String str,char ch[]){
str="test ok";
ch[0]='g';
}
}
A.good and abc
B.good and gbc
C.test ok and abc
D.test ok and gbc
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货