1. Trang chủ
  2. » Công Nghệ Thông Tin

Tài liệu Test Corejava ppt

7 475 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Test Corejava
Chuyên ngành Core Java
Thể loại Test
Năm xuất bản 2002
Định dạng
Số trang 7
Dung lượng 134 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

13 Which of the following modifiers must be present for a method inside the main class to be called inside the main method?. [0.5] a It is only executed after a catch clause has executed

Trang 1

Test Corejava 1) Which of the following is a correct signature for the main method? [0.5] a) static void main(String[] args[]) c) public void main(String[] args)

*b) public static void main(String[] args) d) public static void main(Strings[] args)

2) What value does readLine() return when it has reached the end of the file? [0.5]

3) Which of the Boolean expressions below is incorrect? (choose 2) [0.5]

*a) (true) && (3 => 4) c) (x > 0) || (x < 0)

b) !(x > 0) && (x > 0) *d) (x != 0) || (x = 0)

4) To declare an int variable number with initial value 2, you write [0.5]

5) What value does read () return when it has reached the end of the file? [0.5]

6) Which of these data type requires the largest amount of memory? [0.5]

7) Suppose x=0 and y=0 what is x after evaluating the expression (y >=0) || (x++ > 0)? [1]

8) Suppose x = 1, y = -1, and z = 1 What is the printout of the following statement?

if (x > 0)

if (y > 0)

System.out.println(“x > 0 and y > 0”);

else if (z > 0)

System.out.println(“x < 0 and z > 0”);

[0.5]

a) x > 0 and y > 0; c) x<0 and z < 0;

*b) x < 0 and z > 0; d) None of the above

2002 / Sem 1 – ACCP 2003 Q.P Page 1 of 7

Trang 2

9) What is y after the following switch statement is executed?

x = 3;

switch (x+3)

{

case 6: y = 0;

case 7: y = 1;

default: y += 2;

}

[0.5]

10) What is sum after the following loop terminates?

int sum = 0;

int item = 0;

do

{

item++;

sum += item;

if (sum > 7) break;

}

while (item < 6);

[1]

11) Analyze the following code:

public class Test

{

public static void main (String args[])

{

int i = 0;

for (i=0; i<11; i++);

System.out.println(i+4);

}

}

[0.5]

a) The program has a syntax error

because of the semicolon (;) on

the for loop line

c) The program compiles despite the semicolon (;)

on the for loop line, and displays 14

*b) The program compiles despite

the semicolon (;) on the for loop

line, and displays 15

d) None of the above

12) What is wrong with the following if statement?(choose 2)

if(i++) {

y = x * z;

x /= 2;

else {

[1]

Trang 3

y = y * y;

++z;

}

a) The if condition should use a prefix

operator instead of a postfix operator *c) There is a missing } before the else.

*b) The if condition must be a boolean

expression, not a numeric expression

d) There is no break statement to allow control

to transfer out of the if statement 13) Which of the following modifiers must be present for a method inside the main class

to be called inside the main method?

[1]

15) What are the three ways in which a thread can enter the waiting state?(choose 3) [0.5]

e) Stop()

16) Which of the following are true about the finally clause of a try-catch-finally

statement?

[0.5] a) It is only executed after a catch clause has executed

b) It is only executed after a catch clause has not executed

*c) It is always executed unless its thread terminates

d) It is only executed if an exception is thrown

17) Which layout manager can divide the container into a grid ? [0.5]

a) System.out.println(Math.floor(-4.7)); *c) System.out.println(Math.ceil(-4.7));

b) System.out.println(Math.round(-4.7)); d) System.out.println(Math.min(-4.7));

19) Which of the following is the super class of these classes - ContainterEvent,

FocusEvent, InputEvent, PaintEvent, WindowEvent Select the one correct answer [1] a) ActionEvent

b) AdjustmentEvent

Trang 4

*c) ComponentEvent

d) ItemEvent

e) TextEvent

f) Event

20) _ and are required attributes that give the size ( in pixels) of the

applet display area

[0.5]

*a) width, height

b) vspace, hspace

c) param name, param value

22) Which of these is a legal definition of a method named m assuming it throws

IOException, and returns void Also assume that the method does not take any

arguments Select all correct answers

[0.5]

*a) void m() throws IOException{} c) void m(void) throws IOException{}

b) void m() throw IOException{} d) m() throws IOException{}

23) The _ class is the superclass of the Exception class [0.5]

24) static void nPrint(String message, int n)

{

while (n > 0)

{

System.out.print(message);

n ;

}

}

What is k after invoking nPrint()?

int k = 2;

nPrint(“A message”, k);

[0.5]

a) 0

b) 1

*c) 2

d) None of the above.

25) What will be printed out if this code is run with the following command line?

Java myprog good morning sir

public class myprog{

Public static void main(String argv[])

{

System.out.println(argv[0])

}

[0.5]

Trang 5

}

a) myprog

*b) good

c) morning

d) Exception raised: “java.lang.ArrayIndexOutOfBoundsException: 2”

26) 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]

a) The buttons will run from left to right along the bottom of the Frame

*b) The buttons will run from left to right along the top of the frame

c) The buttons will not be displayed

d) Only button three will show occupying all of the frame

27) Which is the correct syntax for to draw a line using the drawLine() method? [0.5]

*a. void drawLine(int startX, int startY, int endX, int endY) c) void drawLine(int startX, int endX)

b void drawLine(int startX, int startY, int startZ)

28) Suppose that f is an instance of Foo

class Foo

{

int i;

static int s;

void imethod()

{ }

static void smethod()

{ }

}

Which of the following statements is

incorrect?

[1]

A System.out.println(Foo.s); *B.System.out.println(Foo.i);

C f.imethod(); D Foo.smethod();

Trang 6

29) Given a component, comp, and a container, cont, that is organized according to a

FlowLayout, which of the following should be used to add comp to the container

[1]

c) cont.addComponent(comp); d) cont.addAllComponents();

30) What is the output of the following code?

public class Test

{

public static void main(String[] args)

{

String s1 = new String("Welcome to Java!");

String s2 = new String("Welcome to Java!");

if (s1 == s2)

System.out.println("s1 is equal to s2");

else

System.out.println("s1 is not equal to s2");

}

}

[0.5]

a s1 is equal to s2

*b s1 is not equal to s2

31) When you implement a method that is defined in a superclass, you _ the original method [0.5]

32) Which of the following statements registers a panel object p as a listener for a button variable jbt? [0.5]

*A jbt.addActionListener(p); C.jbt.addActionEventListener(p);

B addActionListener(p); D jbt.addEventListener(p);

33) Which of the following statements will not convert a string s into an integer? [0.5]

A i = Integer.parseInt(s); C i = Integer.valueOf(s).intValue();

B i = (new Integer(s)).intValue(); *D i = Integer.valueOf(s);

34) The interface should be implemented to listen for a button action event [0.5]

B MouseListener D WindowListener

35 The method sets the font (Helvetica, 20-point bold) in Graphics object g [0.5]

A g.setFont(new Font("Helvetica", Font.bold, 20)) C g.setFont(new Font("helvetica", BOLD, 20))

*B g.setFont(new Font("Helvetica", Font.BOLD, 20)) D g.setFont(Font("Helvetica", Font.BOLD, 20)) 36) The default layout out of a contentPane in a Frame is [0.5]

Trang 7

*B.BorderLayout D None of the above

*A FlowLayout C BorderLayout

B GridLayout D None of the above

A have a main() method C are executed from the HTML file

B are executed using the java

command

*D are compiled using the javac command

39) The method is executed when the page becomes inactive [0.5]

40) To get the x coordinate of the mouse pointer for the MouseEvent evt, you use (choose 2) [0.5]

*B evt.getPoint().x D None of the above

Ngày đăng: 13/12/2013, 07:15

TỪ KHÓA LIÊN QUAN

w