Android复习

1.关于以下程序代码的说明,正确的一项是()

Line 1:class HashSTaticTest{
Line 2:private static int x=10;
Line 3:pulic static void main(String args[]){
Line 4:HashStaticTest hs1=new HashStaticTest();
Line 5:hs1.x++;
Line 6:HashStaticTest hs2=new HashStaticTest();
Line 7:hs2.x++;
Line 8:hs1=new HashStaticTest();
Line 9:hs1.x++;
Line 10:HashStaticTest.x--;
Line 11:System.out.println(“x=”+x);
Line 12: }
Line 13:}
A.
5行不能通过编译,因为引用了私有静态变量
B.
10行不能通过编译,因为x 是私有静态变量
C.
程序通过编译,输出结果:x=13
D. 程序通过编译,输出结果:x=12
正确答案:D
2.
下列方法中不属于TimePicker控件的方法是()。
A.
voidsetCurrentHour(int hour)
B.
voidsetCurrentMinute(int minute)
C.
setOnTimeSetListener(OnTimeSetListener listener)
D.
setOnTimeChangedListener(OnTimeChangedListener listener)
正确答案:C
3. 如何将Activity设置成窗口样式
A. 在AndroidManifext.xml 中Activity定义添加android:theme="@android:style/Theme.Dialog"
B. 在AndroidManifext.xml 中Activity定义添加android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
C. 在Activity的onCreate方法中设置 requestWindowFeature(Window.FEATURE_NO_TITLE);
D. 在Activity的onCreate方法中设置getWindow().setFlags(https://www.360docs.net/doc/917107044.html,youtParams.FLAG_FULLSCREEN, https://www.360docs.net/doc/917107044.html,youtParams.FLAG_FULLSCREEN);
正确答案:A
4.
程序的执行结果是:
public class Test {
public static void main(String [] args){
System.out.println(“”+'a'+1);
}
}
A.
98
B.
a1
C.
971
D. 197
正确答案:B
5.
下列属性中不属于RadioGroup的方法的是()。
A.
getCheckedRadioButtonId()


B.

setChecked(int id)


C.

getChildCount()


D.

setOnCheckedChangeListener(OnCheckedChangeListener l)


正确答案:B
6.

有变量声明如下:

short b = 120;

下列语句中,错误的是()。
A.

short s = b;


B.

int i = b;


C.

byte s1 = b;




D. long l = b;
正确答案:C
7.

关于CheckedTextView,下列说法正确的是()
A.

当android:checkMark属性的值为?android:attr/listChoiceIndicatorSingle时选择模式为单选
B.

当android:checkMark属性的值为singleChoiceIndicatorMultiple时选择模式为多选
C.

当android:checkMark属性的值为singleChoiceIndicator时选择模式为单选
D.

当android:checkMark属性的值为?android:attr/MultipleChoiceIndicator时选择模式为单选
正确答案:A
8.

阅读以下程序选择正确答案:()

public class foo {

public static void main (String[]args){

Integer t1=127,t3=128;

Integer t2=127,t4=128;

System.out.println(t1==t2);

System.out.println(t1.equals(t2));

System.out.println(t3==t4);



System.out.println(t3.equals(t4));

}

}


A. true,true,true,true
B. false,true,false,true
C. true,true,false,true
D. 编译失败
正确答案:C
9.

下列代码编译和运行的结果是:
public class A {
void process() throws Exception {
throw new Exception();
}
public static void main(String[] args) {
A a = new B();
a.process();
}
}
class B extends A {
void process() {
System.out.println("B ");
}
}
A.

输出:B


B.

无输出


C.

B类的process方法处,出现编译错误


D. 代码a.process();行,出现编译错误
正确答案:D
10.

执行下列语句:

int num=~3+2; 变量num的值为()。
A. -3
B. 3
C. -2
D. -1
正确答案:C
11.

下列代码运行的结果是()。


public class Base {

public static final String FOO = "foo";

public static void main(String[] args) {

Base b = new Base();

Sub s = new Sub();

System.out.print(Base.FOO);

System.out.print(Sub.FOO);

System.out.print(b.FOO);

System.out.print(s.FOO);

System.out.print(((Base) s).FOO);

}

}

class Sub extends Base {

public static final String FOO = "bar";

}
A.

Foofoofoofoofoo




B.

Foobarfoobarbar




C.

Foobarfoofoofoo




D. Foobarfoobarfoo
正确答案:D
12.

关于下列代码说法正确的是:
class ClassA {
public int numberOfinstances;
protected ClassA(int numberOfinstances) {
this.numberOfinstances = numberOfinstances;
}
}
public class ExtendedA extends ClassA {
private ExtendedA(int numberOfinstances) {
super(numberOfinstances);
}
public static void main(String[] args) {
ExtendedA ext = new ExtendedA(420);
System.out.print(ext.numberOfinstances);
}
}
A.

运行后,输出420




B.

运行时抛出异常




C.

编译错误,所有的构造器必须是public的




D. 编译错误,构造器不能是private的
正确答案:A
13.

选择布局代码的正确展现形式


android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2"
android:orientation="horizontal" >

android:layout_width="fill_parent"
android:layout_weight="1"
android:background="#fff453"
android:text="A"
android:textColor="#000000"
android:gravity="center"
android:textSize="35dp"
android:layout_height="fill_parent"
/>
android:text="B"
android:textColor="#000000"
android:gravity="center"
android:textSize="35dp"
android:layout_width="fill_parent"
android:layout_weight="1"
android:background="#f22453"
android:layout_height="fill_parent"
/>

A. AA


B. BB

C. CC

D. DD
正确答案:C
14.

请看下列代码编译和运行的结果是()。



interface DeclareStuff {

public static final int EASY = 3;

void doStuff(int t);

}

public class TestDeclare implements DeclareStuff {

public static void main(String[] args) {

int x = 5;

new TestDeclare().doStuff(++x);

}

void doStuff(int s) {

s += EASY + ++s;

System.out.println("s=" + s);

}

}
A.

s=14





B.

s=16




C.

s=10




D. 编译失败
正确答案:D
15.

阅读以下程序输出正确答案:()


public class foo {

public static void main (String[]args){

List lst=new ArrayList();

lst.add(1);

lst.add(new Integer(2));

lst.add(1,3)

System.out.println(lst)

}

}


A. [1,2,3]
B. [1,3]
C. [1,3,2]
D. 编译失败
正确答案:C
16. 阅读以下程序选择正确答案:()


public class Test {

public static void main (String[]args){

Map map=new HashMap();

map.put(1,”A”);

map.put(2,null);

map.put(null,“B”);

System.out.println(map);

}

}


A. 程序编译正确,其输出结果为: [null=B,1=A,2=null]
B. map 集合中值不能为null
C. map集合中的键不允许为null
D. 编译失败
正确答案:D
17.

请问下列代码的执行结果是:

class Base{

void Test( ){

System.out.println(“Base.test()”);

}

}

public class Child extends Base{

void test(){

System.out.println(“Child.test()”);

}

public static void main(String[] a){

Child child=new Child();

Base base=new child();

Base.test();

}

}
A.

Child.test() Base.test()
B.

Base.test() Child.test()
C.

Base.test()


D. Child.test()
正确答案:D
18.

以下程序正确的输出结果为:()


class StringDemo{

public static void main(String []args){

String m1=”HelloWorld”;

String m2=new String(“HelloWorld”);

System.out.println(m1==m2);

System.out.println(m1.equals(m2));

String m3=new String(“HelloWorld”);

System.out.println(m2==m3);

}
}


A. true,true,true
B. false,true,true
C. false,true,false
D. true,true,false
正确答案:C
19.

程序执行的结果是()。

public class Test {

String name="Tom";

public Test(String name){

name=name;

}

public static void main(String [] args){

Test t = new Test("Jack");

System.out.println(https://www.360docs.net/doc/917107044.html,);

}

}
A.

Null




B.

Tom




C.

Jack




D. " "
正确答

案:B
20.

下列属性中专属于RelativeLayout布局的是()。
A.

android:layout_weight
B.

android:layout_below
C.

android:stretchColumns
D.

android:layout_x
正确答案:B
21.

请问以下API哪个可以在构建对象时指定编码方式呢()



A.

java.io.InputStream


B.

java.io.OutputStream



C.

java.io.InputStreamReader


D. java.io.BufferedInputStream
正确答案:D
22. HashTable 类实现了以下接口的哪些接口:()
A. java.util.Map
B. java.util.List
C. java.util.Set
D. java.uti.Collection
正确答案:A
23.

阅读以下程序输出正确答案:()


public class Test {

public static void main (String[]args){

Set lst=new HashSet();

lst.add(1);

lst.add(new Integer(2));

lst.add(1,3)

System.out.println(lst)

}

}


A. [1,2,3]
B. [1,3]
C. [1,3,2]
D. 编译失败
正确答案:D
24.

分析如下代码,输出结果为()。

public static void main(String[] args) {

int i = 0;

boolean re = false;

re = ((++i) + i == 2) ? true : false;

System.out.println("i=" + i + ",re="+re);

}
A.

i=1,re=true




B.

i=0,re=true




C.

i=1,re=false




D. i=0,re=false
正确答案:A
25.

下列代码的输出结果是()。

public static void main(String[] args) {

int[] one=new int[]{4,6,8};

int[] two=new int[]{1,3,5,7,9};

System.arraycopy(one, 1, two, 2, 2);

System.out.println(Arrays.toString(two));

}
A.

[1, 3, 7, 4, 6]




B.

[1, 3, 5, 7, 8]


C.



[1, 3, 5, 6, 9]




D. [1, 3, 6, 8, 9]
正确答案:D
26.

在<插入代码>处,填入下列代码编译正确的是:
public void foo(int[] x) {
<插入代码>
}
A.

foreach(int z : x) System.out.println(z);
B.

for(int z : x) System.out.println(z);
C.

while( x.hasNext()) System.out.println( x.next());
D.

for( int i=0; i< x.length; i++ ) System.out.println(x[i]);
正确答案:D
27.

阅读以下程序选择说法正确的选项()


public class Test {

public static void main (String args[]) {

class Foo {

public int i = 3;

}

Object o = (Object) new Foo();

Foo foo = (Foo)o;

System.out.println(foo. i);

}
}


A. 编译失败
B. 出现运行出现类型转换异常
C. 程序运行正确输出结果为3
D. 类Foo为局部内部类
正确答案:D
28.

下列不属于Java运算符的是()。
A.

!=
B.

<>
C.

>>
D.

<<
正确答案:B
29.

请看下列代码:
interface Foo {
int bar();
}
public class Sprite {
public int fubar(Foo foo) {
return foo.bar();
}
public void testFoo() {
fubar(
<插入代码>
);
}
}


使类Sprite编译通过,在<插入代码>处应填入的代码是:
A.

Foo { public int bar() { return 1; } }




B.

new Foo { public int bar() { return 1; } }




C.

new Foo() { public int bar(){return 1; } }




D. new class Foo { public int bar() { return 1; } }
正确答案:C
30.

下列代码的运行结果是:
public class GoTest {
public static void main(String[] args) {
Sente a = new Sente();
a.go();
Goban b = new Goban();
b.go();
Stone c = new Stone();
c.go();
}
}
class Sente implements Go {
public void go() {
System.out.println("go in Sente");
}
}
class Goban extends Sente {
public void go() {
System.out.println("go in Goban");
}
}
class Stone extends Goban implements Go {
}
interface Go {
public void go();
}
A.

go in Goban
go in Sente
go in Sente
B.

go in Sente
go in Sente
go in Goban
C.

go in Sente
go in Goban
go in Goban
D.

go in Goban
go in Goban
go in Sente
正确答案:C
31. 在Android中,下面那种布局方式不推荐使用
A. FrameLayout(框架布局)
B. LinearLayout (线性布局)
C. AbsoluteLayout(绝对布局)
D. RelativeLayout(相对布局)
E. TableLayout(表格布局)
正确答案:C
32.

下列代码的输出结果是()。



int j=0;

for(int i=0;i<100;i++){

j=j++;

}

System.out.println(j);
A. 0
B. 99
C. 100
D. 101
正确答案:A
33.

请看下列代码的输出结果是:
public class Bootchy {
int bootch;
String snootch;
public Bootchy() {
this("snootchy");
System.out.print("first ");
}
public Bootchy(String snootch) {
this(420, "snootchy");
System.out.print("second ");
}
public Bootchy(int bootch, String snootch) {
this.bootch = bootch;
this.snootch = snootch;
System.out.print("third ");
}
public static void main(String[] args) {
Bootchy b = new Bootchy();
System.out.print(b.snootch + " " + b.bootch);
}
}
A.

first second third snootchy 420




B.

third second first snootchy 420




C.

third first second snootchy 420




D. first second first third snootchy 420
正确答案:B
34.

以下程序的输出结果正确的是。

public class test {

public static void main(String args[]) {

int x=1,y=1,z=1;

if(x--==1&&y++==1||z++==1)

System.out.println("x="+x+",y="+y+",z="+z);

}
}


A. x=0,y=2,z=1
B. x=1,y=2,z=1
C. x=0,y=1,z=1
D. x=0,y=2,z=2
正确答案:A
35.

以下程序的输出结果为:()


import java.util.*;

public class SortOf {

public static void main(String[] args) {

ArrayList a = new ArrayList();

a.add(1); a.add(5); a.add(3);

Collections.sort(a);

a.add(2);

Collections.reverse(a);

System.out.println(a);

}
}


A. [1,2,3,5]
B. [2,1,3,5]
C. [2,5,3,1]
D. [1,3,5,2]

正确答案:C
36.

下列代码中关于this的用法,说法正确的是()

public class Person{

private int age;

Person(){

this(20); // 1处

}

Person(int age ){

this.age=age; // 2处

}

}
A.

//1 处this的用法是调用 Person(int age){}方法,必须放在Person(){}方法的第一句
B.

//2 处this的用法是区分局部变量和成员变量
C.

//1 处this的用法是调用 Person(int age){}方法,必须放在Person(){}方法的第二句
D.

//2 处this没什么作用,写和不写没什么差别
正确答案:AB
37.

与下面函数构成重载关系的选项为:()

public class GlobalTest{

public GlobalTest(int x,int y){



}

}

A.

GlobalTest(){ }


B.

protected int GlobalTest(){ }


C.

private GlobalTest(int z,int y,int x){ }


D. public void GlobalTest(byte x,byte y,byte z)
正确答案:AC
38.

在下面的程序中,/*插入代码*/处可以插入哪些关键字()

public interface Status{

public interface Status{

/*插入代码*/ int MY_VALUE=100;

}

}
A.

final


B.

static


C.

public


D. private
正确答案:ABC
39. 下列赋值语句中,正确的是()。
A. char c1=’A’;
B. char c2=65;
C. char c3=’abc’;
D. char c4=’\u0041’;
正确答案:ABD
40.

下列与数组有关的javaScript语句中,语法错误的是()
A.

var arr-new Array(10);
B.

var an=new Array[10];
C.

var arr1=[1,2,3]; var arr2=[‘TARENA’,arr1,[10,20]];
D.

var arr=[10,20,30]; for (int i=1;i<=arr.length;i++){ alert(arr[i]); }
正确答案:BD
41.

冒泡排序原理:

a 逐一比较数组中相邻的两个元素, 如果后面的数字小于前面的数字, 就交换先后元素.

b 经过一个轮次的比较, 一定有一个最大的排在最后的位置.

c 每次比较剩下的元素, 最多经过n-1次比较, 可以实现排序
简单说: 比较相邻元素,大的向后交换。



public static void main(String args[]) {
空白处1 (定义一个整型数组并初始化,要求数据位1,7,6,2,5,4,3)
for (int i = 0; 空白处2 ; i++) { //控制比较的轮数
for (int j = 0; 空白处3 ; j++) {//控制比较每轮比较的次数
if ( 空白处4 ) {
int t = ary[j];
空白处5
ary[j + 1] = t;
}
System.out.println();
}
}
}
(1). 以上程序中空白1区域可以填入的数据为:()
A. int ary=[1,7,6,2,5,4,3];
B. int []ary={1,7,6,2,5,4,3}
C. int ary[7]={1,7,6,2,5,4,3}
D. int []ary=new int[7]{1,7,6,2,5

,4,3}
正确答案:B
(2). 以上程序中空白2处可以填写代码为:()
A. iB. iC. iD. i正确答案:A
(3). 以上程序中空白3处可以填写的代码为:()
A. jB. jC. jD. j正确答案:C
(4). 以上程序中空白4处可以填写的代码为:()
A. a[j]>a[j+1]
B. a[j]C. a[i]>a[j+1]
D. a[i]正确答案:A
(5). 以上程序中空白5处可以填写的代码为:()
A. a[j+1]=a[j]
B. a[j]=a[j+1]
C. a[i+1]=a[j]
D. a[i]=a[j+1]
正确答案:C
42.

从一个student文件中读取学生信息(文件中学生信息的格式为1001/gsd1210/90,其中一行为一个学生信息,一个学生信息对应一个Student对象),将这些学生信息按照班级进行分类存储到Map集合中,其中键为班号,其值为List集合,这个集合存储着相同班号的所有学生。

class Student{

private String id;//学生编号

private String classes;//班级号

private int score;//学生成绩

public Student(String id, String classes, int score) {

this.id = id;

this.classes = classes;

this.score = score;

}

//省略set/get方法…..

}

class EntityContext{

private Map> stuMap;

public EntityContext(){

空白处1

loadStudents("student.txt");

}

public void loadStudents(String fileName){

File file=new File(fileName);

BufferedReader br=null;

try {

空白处2

String str=null;

Student student=null;

while( 空白处3 ){

student=parseStudent(str);

addMap(student);

}

} catch (Exception e) {

e.printStackTrace();

}

}

private Student parseStudent(String str){

String s[]=str.split("/");

return new Student(s[0],s[1],Integer.parseInt(s[2]));

}

public void addMap(Student student){

String key=student.getClasses();

if( 空白处4 ){

this.stuMap.get(key).add(student);

}else{

List list=new ArrayList();

list.add(student);

this.stuMap.put(key, list);

}

}

public Map getScore(){//计算每个班级的平均成绩


Set>> ens=this.stuMap.entrySet();

Map stuScore=new HashMap();

for(Entry> e:ens){

int score=0;

for(Student s:e.getValue()){

score+=s.getScore();

}

空白处5(此处将班级平均成绩存储到stuScore)

stuScore.put(e.getKey(), score*1.0/e.getValue().size());

}

return stuScore;

}

}

public class TestStudent {

public static void main(String[] args) {

EntityContext context=new EntityContext();

System.out.println(context.getScore()));

}
}
(1). 下列选项中,在横线空白处1的位置给stuMap赋值,用于存储学生信息()。
A. stuMap=new HashMap>()
B. stuMap=new HashMap>()
C. stuMap=new Map>()
D. stuMap=new ArrayList()
正确答案:A
(2). 下列选项中,在横线空白处2的位置给变量br赋值,其代码可以为()。
A. br=new BufferedReader(file)
B. br=new BufferedReader(new InputStreamReader(file))
C.

br=new BufferedReader(new InputStreamReader(new
FileInputStream(file),”utf-8”))
D. br=new BufferedReader(new FileReader(file,”utf-8”))
正确答案:C
(3). 下列选项中,在横线空白3处可以填写的代码为()。
A. (str=br.read())!=-1
B. (str=br.read())!=null
C. (str=br.readLine())!=-1
D. (str=br.readLine())!=null
正确答案:D
(4). 下列选项中,在横线空白4处可以填写的代码为()。
A. this.stuMap.containsKey(key);
B. this.stuMap.contains(key);
C. this.stuMap.containsVlue(key);
D. this.stuMap.getValue(key);
正确答案:A
(5). 下列选项中,在横线空白5处,可以填写的代码为()。
A. stuScore.put(e.getKey(), score/e.getValue().size())
B. stuScore.put(e.getKey(), score*1.0/e.getValue().size())
C. stuScore.put(e.getKey(), score)
D. stuScore.put(e.getKey(), score*1.0)
正确答案:B

相关文档
最新文档