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
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
what will happen when you attempt to compile and run this code
//demonstration of event handling
import java.awt.*;
import java.awt.event.*;
public class mywc extends frame implements windowlistener{
public static void main(string argv[]){
mywc mwc = new mywc();
}
public void windowclosing(windowevent we){
system.exit(0);
}//end of windowclosing
public void mywc(){
setsize(300,300);
setvisible(true);
}
}//end of class
1) error at compile time
2) visible frame created that that can be closed
3) compilation but no output at run time
4) error at compile time because of comment before import statements
which option most fully describes will happen when you attempt to compile and run the following code
public class myar{
public static void main(string argv[]) {
myar m = new myar();
m.amethod();
}
public void amethod(){
static int i;
system.out.println(i);
}
}
1) compilation and output of the value 0
2) compile time error because i has not been initialized
3) compilation and output of null
4) compile time error
which of the following will compile correctly
1) short myshort = 99s;
2) string name = 'excellent tutorial mr green';
3) char c = 17c;
4)int z = 015;
which of the following are java key words
1)double
2)switch
3)then
4)instanceof
what will be output by the following line?
system.out.println(math.floor(-2.1));
1) -2
2) 2.0
3) -3
4) -3.0
given the following main method in a class called cycle and a command line of
java cycle one two
what will be output?
public static void main(string bicycle[]){
system.out.println(bicycle[0]);
}
1) none of these options
2) cycle
3) one
4) two
which of the following statements are true?
1) at the root of the collection hierarchy is a class called collection
2) the collection interface contains a method called enumerator
3) the interator method returns an instance of the vector class
4) the set interface is designed for unique elements
which of the following statements are correct?
1) if multiple listeners are added to a component only events for the last listener added will be processed
2) if multiple listeners are added to a component the events will be processed for all but with no guarantee in the order
3) adding multiple listeners to a comnponent will cause a compile time error
4) you may remove as well add listeners to a component.
责任编辑:小草