Edzy_Java

  BlogJava :: 首页 ::  ::  ::  :: 管理 ::
  58 随笔 :: 12 文章 :: 11 评论 :: 0 Trackbacks

JAVA题库:格林模拟试题三
Questions
________________________________________
Question 1)Which of the following are legal statements?

1) float f=1/3;

2) int i=1/3;

3) float f=1.01;

4) double d=999d;
________________________________________

Question 2)Which of the following are Java keywords?

1) NULL

2) new

3) instanceOf

4) wend
________________________________________

Question 3)Which of the following are valid statements?

1) System.out.println(1+1);

2) int i=2+'2';

3) String s="on"+'one';

4) byte b=255;
________________________________________

Question 4)Which of the following statements are true?

1) The garbage collection algorithm in Java is vendor implemented

2) The size of primitives is platform dependent

3) The default type for a numerical literal with decimal component is a float.

4) You can modify the value in an Instance of the Integer class with the setValue method
________________________________________

Question 5)Which of the following are true statements?

1) I/O in Java can only be performed using the Listener classes

2) The RandomAccessFile class allows you to move directly to any point a file.

3) The creation of a named instance of the File class creates a matching file in the underlying operating system only when the close method is called.

4) The characteristics of an instance of the File class such as the directory separator, depend on the current underlying operating system
________________________________________

Question 6)Which of the following statements are true?

1) The instanceof operator can be used to determine if a reference is an instance of a class, but not an interface.

2) The instanceof operator can be used to determine if a reference is an instance of a particular primitive wrapper class

3) The instanceof operator will only determine if a reference is an instance of a class immediately above in the hierarchy but no further up the inheritance chain

4) The instanceof operator can be used to determine if one reference is of the same class as another reference thus
________________________________________

Question 7)Which of the following statements are true?

1) An interface can only contain method and not variables

2) Interfaces cannot have constructors

3) A class may extend only one other class and implement only one interface

4) Interfaces are the Java approach to addressing its lack of multiple inheritance, but require implementing classes to create the functionality of the Interfaces.
________________________________________

Question 8)Which of the following are valid statements

1) public class MyCalc extends Math

2) Math.max(s);

3) Math.round(9.99,1);

4)Math.mod(4,10);
________________________________________

Question 9)Which of the following are methods of the Runnable interface

1) run

2) start

3) yield

4) stop
________________________________________

Question 10)Which of the following statements are true?

1) A byte can represent between -128 to 127

2) A byte can represent between -127 to 128

3) A byte can represent between -256 to 256

4) A char can represent between -2x2 pow 16 2 x2 pow 16 - 1
________________________________________

Question 11)What will happen when you attempt to compile and run the following code

class Base{

public void Base(){

System.out.println("Base");

}

}

public class In extends Base{

public static void main(String argv[]){

In i=new In();

}

}

1) Compile time error Base is a keyword

2) Compilation and no output at runtime

3) Output of Base

4) Runtime error Base has no valid constructor
________________________________________

Question 12)You have a public class called myclass with the main method defined as follows

public static void main(String parm[]){

System.out.println(parm[0]);

}

If you attempt to compile the class and run the program as follows

java myclass hello

What will happen?

1) Compile time error, main is not correctly defined

2) Run time error, main is not correctly defined

3) Compilation and output of  java

4) Compilation and output of hello
________________________________________

Question 13)Which of the following statements are true?

1) If a class has any abstract methods it must be declared abstract itself.

2) All methods in an abstract class must be declared as abstract

3) When applied to a class, the final modifier means it cannot be sub-classed

4) transient and volatile are Java modifiers
________________________________________

Question 14)Which of the following are valid methods?

1) public static native void amethod(){}

2) public static void amethod(){}

3) private protected void amethod(){}

4) static native void amethod();
________________________________________

Question 15)Which of the following statements are true?

1) Constructors cannot have a visibility modifier

2) Constructors can be marked public and protected, but not private

3) Constructors can only have a primitive return type

4) Constructors are not inherited
________________________________________

Question 16)What will happen when you attempt to compile and run the following class?

class Base{

Base(int i){System.out.println("Base");}

}

class Severn extends Base{

public static void main(String argv[]){Severn s = new Severn();}

void Severn(){System.out.println("Severn");}

}

1) Compilation and output of the string "Severn" at runtime

2) Compile time error

3) Compilation and no output at runtime

4) Compilation and output of the string "Base"
________________________________________

Question 17)Which of the following statements are true?

1) static methods do not have access to the implicit variable called this

2) A static method may be called without creating an instance of its class

3) A static method may not be overriden to be non-static

4) A static method may not be overloaded
________________________________________

Question 18)Which of the following will compile without error?

1)char c='1';

System.out.println(c>>1);

2)Integer i=Integer("1");

System.out.println(i>>1);

3)int i=1;

System.out.println(i<<<1);

4)int i=1;

System.out.println(i<<1);
________________________________________

Question 19)Which of the following are true?

1) A component may have only one event listener attached at a time

2) An event listener may be removed from a component

3) The ActionListener interface has no corresponding Adapter class

4) The processing of an event listener requires a try/catch block
________________________________________

Question 20)Which of the following are Java keywords?

1) sizeof

2) main

3) transient

4) volatile
________________________________________

Question 21)Which of the following statements are true?

1) The default constructor has a return type of void

2) The default constructor takes a parameter of void

3) The default constructor takes no parameters

4) The default constructor is not created if the class has any constructors of its own.
________________________________________

Question 22)Which of the following statements are true?

1) All of the variables in an interface are implicitly static

2) All of the variables in an interface are implicitly final

3) All of the methods in an interface are implicitly abstract

4) A method in an interface can access class level variables
________________________________________

Question 23)Which of the following statements are true?

1) The String class is implemented as a char array, elements are addressed using the stringname[] convention

2) The + operator is overloaded for concatenation for the String class

3) Strings are a primitive type in Java and the StringBuffer is used as the matching wrapper type

4) The size of a string can be retrieved using the length property
________________________________________

Question 24)Which of the following statements are true?

1) A method in an interface must not have a body

2) A class may extend one other class plus at most one interface

3) A class may extends at most one other class plus implement many interfaces

4) An class accesses an interface via the keyword uses
________________________________________

Question 25)Which of the following statements are true?

1) The following statement will produce a result of 1. System.out.println( -1 >>>2);

2) Performing an unsigned left shift (<<<) on a negative number will always produce a negative number result

3) The following statement will produce a result of zero, System.out.println(1 >>1);

4) All the Java integral types are signed numbers
________________________________________

Question 26)Which of the following statements are true?

1) The elements in a Java array can only be of primitive types, not objects

2) Arrays elements are initialized to default values wherever they are created using the keword new

3) An array may be dynamically resized using the setSize method

4) You can find out the size of an array using the size method
________________________________________

Question 27)Given the following class

public class Ombersley{

public static void main(String argv[]){

boolean b1 = true;

if((b1 ==true) || place(true)){

System.out.println("Hello Crowle");

}

}

public static boolean place(boolean location){

if(location==true){

System.out.println("Borcetshire");

}

System.out.println("Powick");

return true;

}

}

What will happen when you attempt to compile and run it?

1) Compile time error

2) Output of "Hello Crowle"

3) Output of Borcetshire and Powick followed by "Hello Crowle"

4) No output
________________________________________

1) d.super().super().move();

2) d.parent().parent().move();

3) d.move();
4) none of the above;
________________________________________

Question 29)Which of the following most closely describes the process of overriding?

1) A class with the same name replaces the functionality of a class defined earlier in the hierarchy

2) A method with the same name completely replaces the functionality of a method earlier in the hierarchy

3) A method with the same name but different parameters gives multiple uses for the same method name

4) A class is prevented from accessing methods in its immediate ancestor
________________________________________

Question 30)Which of the following statements are true?

1) The % is used to calculate a percentage thus: 10 % 20=50

2) The / operator is used to divide one value by another

3) The # symbol may not be used as the first character of a variable

4) The $ symbol may not be used as the first character of a variable
________________________________________

Question 31)Which of the following statements are true?

1) The default layout manager for an Applet is FlowLayout

2) The default layout manager for a Frame is FlowLayout

3) A layout manager must be assigned to an Applet before the setSize method is called

4) The FlowLayout manager attempts to honor the preferred size of any components
________________________________________

Question 32)Which of the following statements are true about a variable created with the static modifier?

1) Once assigned the value of a static variable may not be altered

2) A static variable created in a method will keep the same value between calls

3) Only one instance of a static variable will exist for any amount of class instances

4) The static modifier can only be applied to a primitive value
________________________________________

Question 33)Which of the following statements are true?

1) Java uses a system called UTF for I/O to support international character sets

2) The RandomAccessFile is the most suitable class for supporting international character sets

3) An instance of FileInputStream may not be chained to an instance of FileOutputStream

4) File I/O activities requires use of Exception handling
________________________________________

Question 34)What will happen when you attempt to compile and run the following code?

import java.io.*;

class ExBase{

abstract public void martley(){}

}

public class MyEx extends ExBase{

public static void main(String argv[]){

DataInputStream fi = new DataInputStream(System.in);

try{

fi.readChar();

}catch(IOException e){

System.exit(0);

}finally {

System.out.println("Doing finally");

}

}

}

1) Compile time error

2) It will run, wait for a key press and then exit

3) It will run, wait for a keypress, print "Doing finally" then exit

4) At run and immediately exit
________________________________________

Question 35)What will happen when you attempt to compile and run the following code

public class Borley extends Thread{

public static void main(String argv[]){

Borley b = new Borley();

b.start();

}

public void run(){
System.out.println("Running");

}

}

1) Compilation and run but no output

2) Compilation and run with the output "Running"

3) Compile time error with complaint of no Thread target

4) Compile time error with complaint of no access to Thread package
________________________________________

Question 36)Assuming any exception handling has been set up, which of the following will create an instance of the RandomAccessFile class

1) RandomAccessFile raf=new RandomAccessFile("myfile.txt","rw");

2) RandomAccessFile raf=new RandomAccessFile( new DataInputStream());

3) RandomAccessFile raf=new RandomAccessFile("myfile.txt");

4) RandomAccessFile raf=new RandomAccessFile( new File("myfile.txt"));
________________________________________

Question 37)Given the following class definition

public class Upton{

public static void main(String argv[]){}

public void amethod(int i){}//Here

}

Which of the following would be legal to place after the comment //Here ?

1) public int amethod(int z){}

2) public int amethod(int i,int j){return 99;}

3) protected void amethod(long l){ }

4) private void anothermethod(){}
________________________________________

Question 38)Which of the following statements are true?

1) Code must be written if the programmer wants a frame to close on selecting the system close menu

2) The default layout for a Frame is the BorderLayout Manager

3) The layout manager for a Frame cannot be changed once it has been assigned

4) The GridBagLayout manager makes extensive use of the the GridBagConstraints class.
________________________________________

Question 39)Given the following class definition

public class Droitwich{

class one{

private class two{

public void main(){

System.out.println("two");

}

}

}

}

Which of the following statements are true

1) The code will not compile because the classes are nested to more than one level

2) The code will not compile because class two is marked as private

3) The code will compile and output the string two at runtime

4) The code will compile without error
________________________________________

Question 40)Given the following code

class Base{

static int oak=99;

}public class Doverdale extends Base{

public static void main(String argv[]){

Doverdale d = new Doverdale();

d.amethod();

}public void amethod(){//Here}
    
}
Which of the following if placed after the comment //Here, will compile and modify the value of the variable oak?

1) super.oak=1;

2) oak=33;

3) Base.oak=22;

4) oak=50.1;
________________________________________

Question 41)You are creating an application that has a form with a text entry field used to enter a persons age. Which of the following is appropriate for capturing this information.

1) Use the Text field of a TextField and parse the result using Integer

2) Use the getInteger method of the TextField

3) Use the getText method of a TextBox and parse the result using the getInt method of Integer class

4) Use the getText method of a TextField and use the parseInt method of the Integer class
________________________________________

Question 42)Given the following declaration

Integer i=new Integer(99);

How can you now set the value of i to 10?

1) i=10;

2) i.setValue(10);

3) i.parseInt(10);

4) none of the above
________________________________________

Question 43)Which of the following statements are true

1) constructors cannot be overloaded

2) constructors cannot be overridden

3) a constructor can return a primitive or an object reference

4) constructor code executes from the current class up the hierarchy to the ancestor class
________________________________________

Question 44)Given a reference called
t

to a class which extends Thread, which of the following will cause it to give up cycles to allow another thread to execute.

1) t.yield();

2) Thread.yield();

3) yield(100); //Or some other suitable amount in milliseconds

4) yield(t);
________________________________________

Question 45)What will happen when you attempt to compile and run the following code?

public class Sandys{

private int court;

public static void main(String argv[]){

Sandys s = new Sandys(99);

System.out.println(s.court);

}

Sandys(int ballcount){

court=ballcount;

}

}

1) Compile time error, the variable court is defined as private

2) Compile time error, s is not initialized when the System.out method is called

3) Compilation and execution with no output

4) Compilation and run with an output of 99
________________________________________

Question 46)Which of the following statements are true?

1) A method cannot be overloaded to be less public in a child class

2) To be overridden a method only needs the same name and parameter types

3) To be overridden a method must have the same name, parameter and return types

4) An overridden method must have the same name, parameter names and parameter types
________________________________________

Question 47)What will happen when you attempt to compile and run the following code?

class Base{

Base(){

System.out.println("Base");

}
}public class Checket extends Base{

public static void main(String argv[]){

Checket c = new Checket();super();

}

Checket(){

System.out.println("Checket"); 

}

}

1) Compile time error

2) Checket followed by Base

3) Base followed by Checket

4) runtime error
________________________________________

Question 48)Which of the following statements are true?

1) Static methods cannot be overriden to be non static

2) Static methods cannot be declared as private

3) Private methods cannot be overloaded

4) An overloaded method cannot throw exceptions not checked in the base class
________________________________________

Question 49)Which of the following statements are true?

1) The automatic garbage collection of the JVM prevents programs from ever running out of memory

2) A program can suggest that garbage collection be performed but not force it

3) Garbage collection is platform independent

4) An object becomes eligible for garbage collection when all references denoting it are set to null.
________________________________________

Question 50)Given the following code

public class Sytch{

int x=2000;

public static void main(String argv[]){

System.out.println("Ms "+argv[1]+"Please pay $"+x);

}

}

What will happen if you attempt to compile and run this code with the command line

java Sytch Jones Diggle

1) Compilation and output of Ms Diggle Please pay $2000

2) Compile time error

3) Compilation and output of Ms Jones Please pay $2000

4) Compilation but runtime error
________________________________________

Question 51)What will happen when you attempt to compile and run the following code

class Base{

protected int i = 99;

}

public class Ab{

private int i=1;

public static void main(String argv[]){

Ab a = new Ab();

a.hallow();

}

abstract void hallow(){

System.out.println("Claines "+i);

}

}

1) Compile time error

2) Compilation and output of Claines 99

3) Compilation and output of Claines 1

4) Compilation and not output at runtime
________________________________________

Question 52)You have been asked to create a scheduling system for a hotel and catering organsiation.

You have been given the following information and asked to create a set of classes to represent it.

On the catering side of the organsiation they have

Head Chefs

Chefs

Apprentice Chefs

The system needs to store an employeeid, salary and the holiday entitlement

How would you best represent this information in Javae been given the following information and asked to create a set of classes to represent it.

How would you best represent this information in Java

1) Create classes for Head Chef, Chef, Apprentice Chef and store the other values in fields

2) Create an employee class and derive sub classes for Head Chef, Chef, Apprentice Chef and store the other values in fields.

3) Create and employee class with fields for Job title and fields for the other values.

4) Create classes for all of the items mentioned and create a container class to represent employees

1) new FileInputStream("file.name")

2) new InputStreamReader(new FileInputStream("file.name"))

3) new BufferedReader(new InputStreamReader(new FileInputStream("file.name")));

4) new RandomAccessFile raf=new RandomAccessFile("myfile.txt","+rw");
________________________________________

Question 54)What will happen when you attempt to compile and run the following code?

public class Inc{

public static void main(String argv[]){I

nc inc = new Inc();

int i =0;

inc.fermin(i);

i = i++;

System.out.println(i);

}void fermin(int i){

i++;

}

}
1) Compile time error

2) Output of 2

3) Output of 1

4) Output of 0
________________________________________

Question 55)What will happen when you attempt to compile and run the following code?

public class Agg{

static public long i=10;

public static void main(String argv[]){

switch(i){

default:System.out.println("no value given");

case 1: System.out.println("one");

case 10:System.out.println("ten");

case 5:System.out.println("five");

}

}

}

1) Compile time error

2) Output of "ten" followed by "five"

3) Output of "ten"

4) Compilation and run time error because of location of default
________________________________________

Question 56)Given the following class

public class ZeroPrint{

public static void main(String argv[]){

int i =0;//Here 

}

}

Which of the following lines if placed after the comment //Here will print out 0.

1) System.out.println(i++);

2) System.out.println(i+'0');

3) System.out.println(i);

4) System.out.println(i--);
________________________________________

Question 57)Given the following code

1) System.out.println(a.getFields());

2) System.out.println(a.name);

3) System.out.println((Base) a.getFields());

4) System.out.println( ((Agg) a).getFields());
________________________________________

Question 58)What will happen when you attempt to compile and run the following code.

public class Pvf{static boolean Paddy;

public static void main(String argv[]){

System.out.println(Paddy);

}

}

1) Compile time error

2) compilation and output of false

3) compilation and output of true

4) compilation and output of null
________________________________________

Question 59)Which of the following statements are true?

1) The x,y coordinates of an instance of MouseEvent can be obtained using the getX() and getY() methods

2) The x,y coordinates of an instance of MouseEvent can be obtained using the X and Y integer fields

3) The time of a MouseEvent can be extracted using the getTime() method

4) The time of a MouseEvent can be extracted using the getWhen method
________________________________________

Question 60)Given the following code

import java.io.*;

public class Ppvg{

public static void main(String argv[]){

Ppvg p = new Ppvg();

p.fliton();}

public int fliton(){

try{

FileInputStream din = new FileInputStream("Ppvg.java");

din.read();

}

catch(IOException ioe){

System.out.println("flytwick");      

return 99;

}

finally{

System.out.println("fliton");

}

return -1;

}

}

Assuming the file Ppvg.java is available to be read which of the following statements are true if you try to compile and run the program?

1) The program will run and output only "flytwick"

2) The program will run and output only "fliton"

3) The program will run and output both "fliton" and "flytwick"

4) An error will occur at compile time because the method fliton attempts to return two values

posted on 2006-11-17 11:30 lbfeng 阅读(718) 评论(0)  编辑  收藏 所属分类: 专业考试题库

只有注册用户登录后才能发表评论。


网站导航:
博客园   IT新闻   Chat2DB   C++博客   博问