JAVA题库:格林模拟试题二(上)

日期:12-29| http://www.59wj.com |二级JAVA模拟试题|人气:593

JAVA题库:格林模拟试题二(上) Question 1)
What will happen when you attempt to compile and run this code?
abstract class Base{    abstract public void myfunc();    public void another(){    System.out.println("Another method");    }}public class Abs extends Base{    public static void main(String argv[]){    Abs a = new Abs();    a.amethod();    }    public void myfunc(){        System.out.println("My Func");        }    public void amethod(){    myfunc();       }}
1) The code will compile and run, printing out the words "My Func"
2) The compiler will complain that the Base class has non abstract methods
3) The code will compile but complain at run time that the Base class has non abstract methods
4) The compiler will complain that the method myfunc in the base class has no body, nobody at all to looove it

Question 2)
What will happen when you attempt to compile and run this code?
public class MyMain{public static void main(String argv){    System.out.println("Hello cruel world");    }}
1) The compiler will complain that main is a reserved word and cannot be used for a class
2) The code will compile and when run will print out "Hello cruel world"
3) The code will compile but will complain at run time that no constructor is defined
4) The code will compile but will complain at run time that main is not correctly defined

Question 3)
Which of the following are Java modifiers?

1) public
2) private
3) friendly
4) transient
5) vagrant www.59wj.com Question 4)
What will happen when you attempt to compile and run this code?
class Base{    abstract public void myfunc();    public void another(){    System.out.println("Another method");    }}public class Abs extends Base{    public static void main(String argv[]){    Abs a = new Abs();    a.amethod();    }    public void myfunc(){        System.out.println("My func");        }    public void amethod(){    myfunc();    }}
1) The code will compile and run, printing out the words "My Func"
2) The compiler will complain that the Base class is not declared as abstract.
3) The code will compile but complain at run time that the Base class has non abstract methods
4) The compiler will complain that the method myfunc in the base class has no body, nobody at all to looove it

Question 5)
Why might you define a method as native?
1) To get to access hardware that Java does not know about
2) To define a new data type such as an unsigned integer
3) To write optimised code for performance in a language such as C/C++
4) To overcome the limitation of the private scope of a method

Question 6)
What will happen when you attempt to compile and run this code?
class Base{public final void amethod(){    System.out.println("amethod");    }}public class Fin extends Base{public static void main(String argv[]){    Base b = new Base();    b.amethod();    }}
1) Compile time error indicating that a class with any final methods must be declared final itself
2) Compile time error indicating that you cannot inherit from a class with final methods
3) Run time error indicating that Base is not defined as final
4) Success in compilation and output of "amethod" at run time. www.59wj.com Question 7)
What will happen when you attempt to compile and run this code?
public class Mod{public static void main(String argv[]){  }    public static native void amethod();}
1) Error at compilation: native method cannot be static
2) Error at compilation native method must return value
3) Compilation but error at run time unless you have made code containing native amethod available
4) Compilation and execution without error

Question 8)
What will happen when you attempt to compile and run this code?
private class Base{}public class Vis{    transient int  iVal;    public static void main(String elephant[]){    }}
1)Compile time error: Base cannot be private
2)Compile time error indicating that an integer cannot be transient
3)Compile time error transient not a data type
4)Compile time error malformed main method

Question 9)
What happens when you attempt to compile and run these two files in the same directory?
//File P1.javapackage MyPackage;class P1{void afancymethod(){    System.out.println("What a fancy method");    }}//File P2.javapublic class P2 extends P1{  public static void main(String argv[]){ P2 p2 = new P2(); p2.afancymethod();  }}
1) Both compile and P2 outputs "What a fancy method" when run
2) Neither will compile
3) Both compile but P2 has an error at run time
4) P1 compiles cleanly but P2 has an error at compile time www.59wj.com Question 10)
You want to find out the value of the last element of an array. You write the following code. What will happen when you compile and run it.?
public class MyAr{public static void main(String argv[]){    int[] i = new int;    System.out.println(i);    }}
1) An error at compile time
2) An error at run time
3) The value 0 will be output
4) The string "null" will be output

Question 11)
You want to loop through an array and stop when you come to the last element. Being a good java programmer and forgetting everything you ever knew about C/C++ you know that arrays contain information about their size. Which of the following can you use?

1)myarray.length();
2)myarray.length;
3)myarray.size
4)myarray.size();

Question 12)
What best describes the appearance of an application with the following code?
import java.awt.*;public class FlowAp extends Frame{public static void main(String argv[]){  FlowAp fa=new FlowAp();  fa.setSize(400,300);  fa.setVisible(true);}FlowAp(){    add(new Button("One"));    add(new Button("Two"));    add(new Button("Three"));    add(new Button("Four"));  }//End of constructor}//End of Application
1) A Frame with buttons marked One to Four placed on each edge.
2) A Frame with buutons marked One to four running from the top to bottom
3) A Frame with one large button marked Four in the Centre
4) An Error at run time indicating you have not set a LayoutManager www.59wj.com Question 13)
How do you indicate where a component will be positioned using Flowlayout?
1) North, South,East,West
2) Assign a row/column grid reference
3) Pass a X/Y percentage parameter to the add method
4) Do nothing, the FlowLayout will position the component

Question 14)
How do you change the current layout manager for a container
1) Use the setLayout method
2) Once created you cannot change the current layout manager of a component
3) Use the setLayoutManager method
4) Use the updateLayout method

Question 15)
Which of the following are fields of the GridBagConstraints class?
1) ipadx
2) fill
3) insets
4) width

Question 16)
What most closely matches the appearance when this code runs?
import java.awt.*;public class CompLay extends Frame{public static void main(String argv[]){  CompLay cl = new CompLay();  }CompLay(){  Panel p = new Panel();  p.setBackground(Color.pink);  p.add(new Button("One"));  p.add(new Button("Two"));  p.add(new Button("Three"));  add("South",p);  setLayout(new FlowLayout());  setSize(300,300);  setVisible(true);  }}
1) The buttons will run from left to right along the bottom of the Frame
2) The buttons will run from left to right along the top of the frame
3) The buttons will not be displayed
4) Only button three will show occupying all of the frame www.59wj.com Question 17)
Which statements are correct about the anchor field?
1) It is a field of the GridBagLayout manager for controlling component placement
2) It is a field of the GridBagConstraints class for controlling component placement
3) A valid setting for the anchor field is GridBagConstraints.NORTH
4) The anchor field controls the height of components added to a container

Question 18)
What will happen when you attempt to compile and run the following code?
public class Bground extends Thread{public static void main(String argv[]){        Bground b = new Bground();        b.run();    }    public void start(){        for (int i = 0; i <10; i++){           System.out.println("Value of i = " + i);        }    }}
1) A compile time error indicating that no run method is defined for the Thread class
2) A run time error indicating that no run method is defined for the Thread class
3) Clean compile and at run time the values 0 to 9 are printed out
4) Clean compile but no output at runtime

Question 19)
Is the following statement true or false?
When using the GridBagLayout manager, each new component requires a new instance of the GridBagConstraints class.
1) true
2) false

Question 20)
Which most closely matches a description of a Java Map?
1) A vector of arrays for a 2D geographic representation
2) A class for containing unique array elements
3) A class for containing unique vector elements
4) An interface that ensures that implementing classes cannot contain duplicate keys

Question 21)
How does the set collection deal with duplicate elements?
1) An exception is thrown if you attempt to add an element with a duplicate value
2) The add method returns false if you attempt to add an element with a duplicate value
3) A set may contain elements that return duplicate values from a call to the equals method
4) Duplicate values will cause an error at compile time www.59wj.com Question 22)
What can cause a thread to stop executing?
1) The program exits via a call to System.exit(0);
2) Another thread is given a higher priority
3) A call to the thread’s stop method.
4) A call to the halt method of the Thread class 
 
Question 23)
For a class defined inside a method, what rule governs access to the variables of the enclosing method?
1) The class can access any variable
2) The class can only access static variables
3) The class can only access transient variables
4) The class can only access final variables

Question 24)

Under what circumstances might you use the yield method of the Thread class
1) To call from the currently running thread to allow another thread of the same or higher priority to run
2) To call on a waiting thread to allow it to run
3) To allow a thread of higher priority to run
4) To call from the currently running thread with a parameter designating which thread should be allowed to run

Question 25)
What will happen when you attempt to compile and run the following code
public class Hope{  public static void main(String argv[]){ Hope h = new Hope();  }  protected Hope(){ for(int i =0; i <10; i ++){   System.out.println(i); }  }}
1) Compilation error: Constructors cannot be declared protected
2) Run time error: Constructors cannot be declared protected
3) Compilation and running with output 0 to 10
4) Compilation and running with output 0 to 9

Question 26)
What will happen when you attempt to compile and run the following code
public class MySwitch{public static void main(String argv[]){  MySwitch ms= new MySwitch();  ms.amethod();  }public void amethod(){  int k=10;    switch(k){    default: //Put the default at the bottom, not here      System.out.println("This is the default output");      break;     case 10:      System.out.println("ten");    case 20:      System.out.println("twenty");    break;    }  }}
1) None of these options
2) Compile time error target of switch must be an integral type
3) Compile and run with output "This is the default output"
4) Compile and run with output of the single line "ten" www.59wj.com Question 22)
What can cause a thread to stop executing?
1) The program exits via a call to System.exit(0);
2) Another thread is given a higher priority
3) A call to the thread’s stop method.
4) A call to the halt method of the Thread class 
 
Question 23)
For a class defined inside a method, what rule governs access to the variables of the enclosing method?
1) The class can access any variable
2) The class can only access static variables
3) The class can only access transient variables
4) The class can only access final variables

Question 24)

Under what circumstances might you use the yield method of the Thread class
1) To call from the currently running thread to allow another thread of the same or higher priority to run
2) To call on a waiting thread to allow it to run
3) To allow a thread of higher priority to run
4) To call from the currently running thread with a parameter designating which thread should be allowed to run

Question 25)
What will happen when you attempt to compile and run the following code
public class Hope{  public static void main(String argv[]){ Hope h = new Hope();  }  protected Hope(){ for(int i =0; i <10; i ++){   System.out.println(i); }  }}
1) Compilation error: Constructors cannot be declared protected
2) Run time error: Constructors cannot be declared protected
3) Compilation and running with output 0 to 10
4) Compilation and running with output 0 to 9

Question 26)
What will happen when you attempt to compile and run the following code
public class MySwitch{public static void main(String argv[]){  MySwitch ms= new MySwitch();  ms.amethod();  }public void amethod(){  int k=10;    switch(k){    default: //Put the default at the bottom, not here      System.out.println("This is the default output");      break;     case 10:      System.out.println("ten");    case 20:      System.out.println("twenty");    break;    }  }}
1) None of these options
2) Compile time error target of switch must be an integral type
3) Compile and run with output "This is the default output"
4) Compile and run with output of the single line "ten" www.59wj.com Question 27)
Which of the following is the correct syntax for suggesting that the JVM performs garbage collection
1) System.free();
2) System.setGarbageCollection();
3) System.out.gc();
4) System.gc();

Question 28)

What will happen when you attempt to compile and run the following code
public class As{  int i = 10;  int j;  char z= 1;  boolean b;  public static void main(String argv[]){ As a = new As(); a.amethod();  }  public void amethod(){    System.out.println(j);    System.out.println(b);          }}
1) Compilation succeeds and at run time an output of 0 and false
2) Compilation succeeds and at run time an output of 0 and true
3) Compile time error b is not initialised
4) Compile time error z must be assigned a char value

Question 29)

What will happen when you attempt to compile and run the following code with the command line "hello there"
public class Arg{String[] MyArg;    public static void main(String argv[]){    MyArg=argv;    }    public void amethod(){        System.out.println(argv[1]);    }}
1) Compile time error
2) Compilation and output of "hello"
3) Compilation and output of "there"
4) None of the above

Question 30)
What will happen when you attempt to compile and run the following code
public class StrEq{public static void main(String argv[]){    StrEq s = new StrEq();    }    private StrEq(){        String s = "Marcus";        String s2 = new String("Marcus");        if(s == s2){           System.out.println("we have a match");           }else{           System.out.println("Not equal");        }    }}
1) Compile time error caused by private constructor
2) Output of "we have a match"
3) Output of "Not equal"
4) Compile time error by attempting to compare strings using www.59wj.com 如果觉得《JAVA题库:格林模拟试题二(上)》二级JAVA模拟试题,jsj不错,可以推荐给好友哦。

本文Tags: 计算机等级考试 - 模拟试题 - 计算机二级模拟试题 - 二级JAVA模拟试题,jsj,
在百度中搜索相关文章:JAVA题库:格林模拟试题二(上)
在谷歌中搜索相关文章:JAVA题库:格林模拟试题二(上)
在soso中搜索相关文章:JAVA题库:格林模拟试题二(上)
在搜狗中搜索相关文章:JAVA题库:格林模拟试题二(上)
相关分类导航|
热门推荐|