JAVA认证格林模拟试题一(下)
来源:优易学  2009-11-28 14:55:06   【优易学:中国教育考试门户网】   资料下载   IT书店
文章页内部300*250广告位

question 31)
what will happen when you attempt to compile and run the following code?
public class holt extends thread{        private string sthreadname;         public static void main(string argv[]){                holt h = new holt();                h.go();         }holt(){}holt(string s){        sthreadname = s;}public string getthreadname(){        return sthreadname;}public void go(){        holt first = new holt("first");        first.start();        holt second = new holt("second");        second.start();}        public void start(){                for(int i = 0; i < 2; i ++){                        system.out.println(getthreadname() +i);                try{                        thread.sleep(100);                        } catch(interruptedexception e){system.out.println(e.getmessage());}                }        }}
1) compile time error
2) output of first0, second0, first0, second1
3) output of first0, first1, second0, second1
4) runtime error
question 32)
an applet has its layout manager set to the default of flowlayout. what code would be correct to change to another layout manager. 
1) setlayoutmanager(new gridlayout()); 
2) setlayout(new gridlayout(2,2)); 
3) setgridlayout(2,2);
4) setborderlayout(); 
question 33)
what will happen when you attempt to compile and run the following code?. 
class background implements runnable{ int i=0;  public int run(){    while(true){     i++;     system.out.println("i="+i);     } //end while       return 1;  }//end run}//end class
1) it will compile and the run method will print out the increasing value of i. 
2) it will compile and calling start will print out the increasing value of i. 
3) the code will cause an error at compile time. 
4) compilation will cause an error because while cannot take a parameter of true.

question 34)

which of the following statements about this code are true?

public class morecombe{
public static void main(string argv[]){
morecombe m = new morecombe();
m.go(new turing(){});
}
public void go(turing t){
t.start();
}

}
class turing extends thread{
public void run(){
for(int i =0; i < 2; i++){
system.out.println(i);
}
}

}


1) compilation error due to malformed parameter to go method
2) compilation error, class turing has no start method
3) compilation and output of 0 followed by 1
4) compilation but runtime error

question 35)
what will be the result when you attempt to compile and run the following code?.

public class conv{
public static void main(string argv[]){
conv c=new conv();
string s=new string("ello");
c.amethod(s);
}

public void amethod(string s){
char c='h';
c+=s;
system.out.println(c);
}
}

1) compilation and output the string "hello"
2) compilation and output the string "ello"
3) compilation and output the string elloh
4) compile time error

question 36)

given the following code, what test would you need to put in place of the comment line?

//place test here

to result in an output of the string equal

public class eqtest{
public static void main(string argv[]){
eqtest e=new eqtest();
}

eqtest(){
string s="java";
string s2="java";
//place test here {
system.out.println("equal");
}else
{
system.out.println("not equal");
}
}
}

1) if(s==s2)
2) if(s.equals(s2)
3) if(s.equalsignorecase(s2))
4) if(s.nocasematch(s2))

question 37)

given the following code

import java.awt.*;
public class setf extends frame{
public static void main(string argv[]){
setf s=new setf();
s.setsize(300,200);
s.setvisible(true);
}

}

how could you set the frame surface color to pink

1)s.setbackground(color.pink);
2)s.setcolor(pink);
3)s.background(pink);
4)s.color=color.pink

question 38)
how can you change the current working directory using an instance of the file class called filename?
1) filename.chdir("dirname")
2) filename.cd("dirname")
3) filename.cwd("dirname")
4) the file class does not support directly changing the current directory.

question 39)

if you create a textfield  with a constructor to set it to occupy 5 columns, what difference will it make if you use it with a proportional font (ie times roman) or a fixed pitch typewriter style font (courier).

1)with a fixed font you will see 5 characters, with a  proportional it will depend on the width of the characters
2)with a fixed font you will see 5 characters,with a  proportional it will cause the field to expand to fit the text 3)the columns setting does not affect the number of characters displayed
4)both will show exactly 5 characters

question 40)
given the following code how could you invoke the base constructor that will print out the string "base constructor";

class base{
base(int i){
system.out.println("base constructor");
}
base(){
}
}

public class sup extends base{
public static void main(string argv[]){
sup s= new sup();
//one
}
sup()
{
//two
}

public void derived()
{
//three
}
}

1) on the line after //one put base(10);
2) on the line after //one put super(10);
3) on the line after //two put super(10);
4) on the line after //three put super(10);

 

[1] [2] [3] 下一页

责任编辑:小草

收藏此页】【 】【打印】【回到顶部
计算机文章页底部500*200广告
文章搜索:
 相关文章
计算机底部580*90广告
文章页右侧第一330*280广告
计算机文章页资讯推荐
热点资讯
文章页330尺寸谷歌广告位
热门课程培训