JAVA题库:格林模拟试题二(下)(1)
文章作者 100test 发表时间 2007:03:14 17:05:42
来源 100Test.Com百考试题网
question 31)
what will happen when you attempt to compile and run the following code
import java.io.*.
class base{
public void amethod()throws filenotfoundexception{}
}
public class excepdemo extends base{
public static void main(string argv[]){
excepdemo e = new excepdemo().
}
public void amethod(){}
protected excepdemo(){
try{
datainputstream din = new datainputstream(system.in).
system.out.println("pausing").
din.readbyte().
system.out.println("continuing").
this.amethod().
}catch(ioexception ioe) {}
}
}
1) compile time error caused by protected constructor
2) compile time error caused by amethod not declaring exception
3) runtime error caused by amethod not declaring exception
4) compile and run with output of "pausing" and "continuing" after a key is hit
question 32)
what will happen when you attempt to compile and run this program
public class outer{
public string name = "outer".
public static void main(string argv[]){
inner i = new inner().
i.showname().
}//end of main
private class inner{
string name =new string("inner").
void showname(){
system.out.println(name).
}
}//end of inner class
}
1) compile and run with output of "outer"
2) compile and run with output of "inner"
3) compile time error because inner is declared as private
4) compile time error because of the line creating the instance of inner