Ôn thi tốt nghiệp: java + uml ( in oop (using java) subject ) Question 1



tải về 0.89 Mb.
trang2/8
Chuyển đổi dữ liệu30.08.2016
Kích0.89 Mb.
#29762
1   2   3   4   5   6   7   8

Question 38–b

Analyze the following code.

public class Test {

public static void main(String[] args) {

Number x = new Integer(3);

System.out.println(x.intValue());

System.out.println(x.compareTo(new Integer(4)));

}

}



  1. The program compiles and runs fine.

  2. The program has a syntax error because x does not have the compareTo method.

  3. The program has a syntax error because an Integer instance cannot be assigned to a Number variable.

  4. The program has a syntax error because intValue is an abstract method in Number.

Question 39–bcd

Analyze the following code:

public class Test {

public static void main(String[] args) {

Set set1 = new HashSet();

set1.add("red");

Set set2 = set1.clone();

}

}



  1. The program compiles and runs and displays nothing.

  2. The program has a compilation error because t is defined in both the main() method and the constructor Test().

  3. The program compiles fine, but it does not run because you cannot use the keyword this in the constructor.

  4. The program compiles and runs and displays test.

Question 40–abe

Analyze the following code:

public class Test {

public static void main(String[] args) {

Set set1 = new HashSet();

set1.add("red");

Set set2 = set1.clone();

}

}



  1. Line 5 is wrong because the decalred type for set1 is Set and the clone method is protected in an instance of Set.

  2. The program will be fine if set1.clone() is replaced by (HashSet)((HashSet)set1).clone()

  3. The program will be fine if set1.clone() is replaced by (LinkedHashSet)((HashSet)set1).clone()

  4. The program will be fine if set1.clone() is replaced by (HashSet)set1.clone()

  5. The program will be fine if set1.clone() is replaced by (Set)((HashSet)set1).clone()

Question 41–bc

Analyze the following code:

ResultSet resultSet = statement.executeQuery

("select firstName, mi, lastName from Student where lastName " + " = 'Smith'");

System.out.println(resultSet.getString(1));


  1. If the SQL SELECT statement returns no result, resultSet is null.

  2. The program will have a runtime error, because the cursor in resultSet does not point to a row. You must use resultSet.next() to move the cursor to the first row in the result set. Subsequently, resultSet.next() moves the cursor to the next row in the result set.

  3. resultSet.getString(1) returns the firstName field in the result set.

  4. resultSet.getString(1) returns the mi field in the result set.

Question 42–e

Analyze the following code.

void looper() {

int x = 0;

one:

while (x<10) {



two:

System.out.println(++x);

if(x>3)

break two;

}

}


  1. This method writes the number 0 to the standard output

  2. the number 4 to the standard output

  3. This code compiles

  4. the number 3 to the standard output

  5. This code does not compile

  6. the numbers 1 and 2 to the standard output

Question 43–b

Analyze the following code and choose the best answer:

public class Foo {

private int x;

public static void main(String[] args) {

Foo foo = new Foo();

System.out.println(foo.x);

}

}



  1. Since x is private, it cannot be accessed from an object foo.

  2. Since x is an instance variable, it cannot be directly used inside a main method. However, it can be accessed through an object such as foo in this code.

  3. Since x is defined in the class Foo, it can be accessed by any method inside the class without using an object. You can write the code to access x without creating an object such as foo in this code.

  4. You cannot create a self-referenced object; that is, foo is created inside the class Foo.

Question 44–d

Analyze the following two classes.

class First {

static int a = 3;

}

final class Second extends First {



void method(){

System.out.println(a);

}

}


  1. Class Second compiles, but class First does not

  2. Class First compiles, but class Second does not

  3. Neither class compiles

  4. Both classes compile, and if method() is invoked, it writes 3 to the standard output

  5. Both classes compile, but if method() is invoked, it throws an exception

Question 45–b

Analyze this line of code:

if(5 7 > 0 & 5|2) System.out.println("true");


  1. this code will compile and write the word "true" in the standard output

  2. this line of code will not compile

  3. this code will compile but nothing will appear in the standard output

Question 46–d

Assume Box is a class with two property variables:

class Box {

private int width;

private int height;

public Box(int w, int h){

width = w;

height = h;

} // end constructor

}//end Box class

aBox and bBox are two reference variables to Box objects with the same height and width:

Box aBox = new Box(10, 40);

Box bBox = new Box(10, 40);

What is the result of evaluating (aBox == bBox) and why?



  1. true, because aBox and bBox refers to the same Box object

  2. not a valid boolean expression

  3. true, because aBox has the same height and width with bBox

  4. false, because aBox and bBox refer to different Box objects. The == operator will only compare references to two objects and will

  5. be true if they refer to the exact same object.

Question 47-b

Assume class A extends class B, that is, class A is defined as:

class A extends B {

....


}// end of class A

Which class is the super class and which one is the subclass?



  1. B is both the super class and subclass

  2. B is the super class, A is the subclass

  3. A is both the super class and subclass

  4. A is the super class, B is the subclass

Question 48–a

Assume class MyFrame is defined as follows:

class MyFrame extends JFrame implements ActionListener{

...


}

Which of the following statements is true about the relationship of MyFrame, JFrame and ActionListener?

a) A MyFrame object IS-A JFrame object, and it also IS-A

ActionListener object.

b) A MyFrame object HAS-A JFrame object, and it also IS-A

ActionListener object.

c) A MyFrame object IS-A JFrame object, and it also HAS-A

ActionListener object

d) A MyFrame object HAS-A JFrame object, and it also HAS-A

ActionListener object.



Question 49–c

Assume f is a reference to a JPanel object. How do you set the size of the JPanel object f refers to a square of (100,100)?



  1. f.setSize(100,100);

  2. f.setPreferredSize(100,100);

  3. f.setPreferredSize(new Dimension(100,100));

  4. f.setSize(new Dimension(100,100));

Question 50–a

Assume methodA is defined as follows:

public void methodA (int [] vals, JLabel display){

// do something

....

}

Which one of the following is a correct way to call methodA?



Assume data is a non-empty reference to an array object, and lbl is a non-empty reference to a JLabel object.

  1. methodA( data, lbl);

  2. methodA( int [] data, lbl);

  3. methodA(data[], lbl);

  4. methodA( data[10], lbl);

Question 51–a

Assume the following method is properly synchronized and called from a thread A on an object B:

wait(2000);

After calling this method, when will the thread A become a candidate to get another turn at the CPU?



  1. After thread A is notified, or after two seconds.

  2. After the lock on B is released, or after two

  3. Two seconds after thread A is notified.

  4. Two seconds after lock B is released.

Question 52–d

Assume x = 5; y = 3; What's the value of y after this while loop?

while(x > 0){

y += 1;


x -=1;

}


  1. 7

  2. 3

  3. –2

  4. 8

Question 53–b

Assume x = 5; y = 3; What's the value of y after this while loop?

while( x > 2 & y > 2) {

x -= 1;


y -= 1;

}


  1. 1

  2. 2

  3. 0

  4. -1

Question 54–d

Assume window is a Container object to the applet's visible region on the screen. Which of the following code cause a button displayed?

a) JButton theButton;

window.add(theButton);

b) JButton theButton = new JButton("ok");

c) JLabel theLabel = new JLabel("ok");

d) JButton theButton = new JButton("ok");

window.add(theButton);



Question 55–c

At which line in the following code is the Vector object, created in line 4, first subject to garbage collection?

1. import java.util.*;

2. public class Question {

3. public static void main(String[] args) {

4. Vector v1 = new Vector();

5. Vector v2 = new Vector();

6. v1 = null;

7. Vector v3 = v1;.

8. v1 = v2;

9. v1.add("This");

10. v1.add(v2);

11. String s = (String) v1.elementAt(0);

12. v1 = v2;

13. v2 = v1;

14. v1.add(s);

15. }

16.}


  1. Line 7

  2. Line 8

  3. Line 6

Question 56–c

_________ checks whether the JCheckBox jchk is selected.



  1. jchk.select()

  2. jchk.getSelected()

  3. jchk.isSelected().

  4. jchk.selected()

Question 57–c

Choose the 1 item below that is not typically listed as a major component of object oriented languages:



  1. Polymorphism

  2. Inheritance

  3. Abstraction

  4. Encapsulation

Question 58–a

Choose the best answer. What is created by lines 6-9 of the Point3D subclass?

3: public class Point3D extends Point {

4: public int z;

5:

6: public Point3D(int x, int y, int z) {



7: super(x,y);

8: this.z = z;

9: }


  1. constructor method

  2. method to extend Point3D

  3. new method called Point3D

Question 59–abd

Choose three. Which of the following are true of a method?



  1. Can return a class of objects

  2. Require parentheses after the name

  3. Defined using brackets [ ]

  4. May or may not return a value when handled

  5. Cannot take arguments

Question 60–abc

Choose three. Which of the following are true of constructors?



  1. They are a special type of method.

  2. They are used to create an object within a class or object.

  3. They are used to set up variables needed for a new object.

  4. They are used to create subclasses.

  5. They cannot take strings as arguments.

Question 61–bc

Choose two. Which of the following are valid reasons for creating an inheritance hierarchy?



  1. Java will do it for you.

  2. It makes it easier to create new programs later.

  3. It actually reduces the amount of coding you have to do.

  4. It's easy to do.

Question 62–bc

Choose two. Which of the following types of collections may have duplicate elements?



  1. Map

  2. List

  3. Collection

  4. Set

Question 63–ab

Choose two. Which statements are true when casting objects in Java?



  1. The source object and destination object must be related by inheritance.

  2. A subclass object can be used in place of a superclass object and vice versa.

  3. Any two Java objects may be used, regardless of inheritance.

  4. A subclass object must be used in place of a superclass object.

Question 64–a

class A {

public static void main (String args[]) {

int h = 0, i = 0, j = 0, k = 0;

label1:

for (;;) {



h++;

label2:


do {

i++;


k = h + i + j;

switch (k) {

default: break label1;

case 1: continue label1;

case 2: break;

case 3: break label2;

case 4: continue label2;

case 5: continue label1;

}

} while (++j<5);



}

System.out.println(h + "," + i + "," + j);

}

}

What is the result of attempting to compile and run the above program?



  1. Prints: 1,3,2

  2. Runtime Exception

  3. Prints: 2,4,2

  4. Prints: 2,2,2

  5. Prints: 2,4,1

  6. Prints: 1,2,3

Question 65–d

class GameComponent { // a game component

public void draw() {

System.out.println("Draw from Base");

}

}

class Ball extends GameComponent {



public void draw() {

System.out.println("Draw from Ball");

}

}

class Paddle extends GameComponent {



int iSize=5;

public void draw() {

super.draw();

System.out.println("Draw from Paddle");

}

public void setSize(int iNewSize) {



this.iSize = iNewSize;

}

}



public class Main {

public static void main(String [] args) {

GameComponent [] gc = new GameComponent [2];

gc[0] = new Ball();

gc[1] = new Paddle();

for (int i=0; i

gc[i].draw();

}

// gc[1].setSize(10);



}

}

The datatype of gc[1] is:



  1. Paddle

  2. Ball

  3. Object

  4. GameComponent

Question 66–c

class GameComponent { // a game component

public void draw() {

System.out.println("Draw from Base");

}

}

class Ball extends GameComponent {



public void draw() {

System.out.println("Draw from Ball");

}

}

class Paddle extends GameComponent {



int iSize=5;

public void draw() {

super.draw();

System.out.println("Draw from Paddle");

}

public void setSize(int iNewSize) {



this.iSize = iNewSize;

}

}



public class Main {

public static void main(String [] args) {

GameComponent [] gc = new GameComponent [2];

gc[0] = new Ball();

gc[1] = new Paddle();

for (int i=0; i

gc[i].draw();

}

// gc[1].setSize(10);



}

}

What is the first line of output from this program?





  1. Draw from Base

  2. Draw from Ball

  3. Draw from Paddle

Question 67–f

class Level1Exception extends Exception {}

class Level2Exception extends Level1Exception {}

class Level3Exception extends Level2Exception {}

class Purple {

public static void main(String args[]) {

int a,b,c,d,f,g,x;

a = b = c = d = f = g = 0;

x = 3;

try {


try {

switch (x) {

case 1: throw new Level1Exception();

case 2: throw new Level2Exception();

case 3: throw new Level3Exception();

}

a++;



}

catch (Level2Exception e) {b++;}

finally{c++;}

}

catch (Level1Exception e) { d++;}



catch (Exception e) {f++;}

finally {g++;}

System.out.print(a+","+b+","+c+","+d+","+f+","+g);

}

}



What is the result of attempting to compile and run the program?

  1. Prints: 1,1,1,0,0,1

  2. Compiler Error

  3. Prints: 0,1,0,0,0,0

  4. Prints: 0,0,1,0,0,1

  5. Prints: 0,1,0,0,0,1

  6. Prints: 0,1,1,0,0,1

Question 68–c

class Level1Exception extends Exception {}

class Level2Exception extends Level1Exception {}

class Level3Exception extends Level2Exception {}

class Purple {

public static void main(String args[]) {

int a,b,c,d,f,g,x;

a = b = c = d = f = g = 0;

x = 3;

try {


try {

switch (x) {

case 1: throw new Level1Exception();

case 2: throw new Level2Exception();

case 3: throw new Level3Exception();

}

a++;



}

finally{c++;}

}

catch (Level1Exception e) { d++;}



catch (Exception e) {f++;}

finally {g++;}

System.out.print(a+","+b+","+c+","+d+","+f+","+g);

}

}



What is the result of attempting to compile and run the program?

  1. Compiler Error

  2. Prints: 0,0,1,0,0,1

  3. Prints: 0,1,1,0,0,1

  4. Prints: 1,1,1,0,0,1

Question 69–abc

Clicking a JComboBox object generates __________ events.



  1. ItemEvent

  2. MouseEvent

  3. ActionEvent

  4. WindowEvent

Question 70–ac

Clicking a JRadioButton generates _____________ events.



  1. ActionEvent

  2. ContainerEvent

  3. ItemEvent

  4. ComponentEvent

Question 71–d

Clicking the closing button on the upper-right corner of a frame generates a(n) __________ event.



  1. ItemEvent

  2. ContainerEvent

  3. ComponentEvent

  4. WindowEvent

  5. MouseMotionEvent

Question 72–d

Consider the following:

class A extends Integer{

int x = 0;

}

Select valid statement.



  1. The code will not compile because class A has no methods or constructor.

  2. The code will compile correctly.

  3. The code will compile correctly, but will throw an ArithmeticException at runtime.

  4. The code will not compile because Integer is final and cannot be subclassed.

Question 73–d

Consider the following application:

1. class Q7 {

2. public static void main(String args[]) {

3. double d = 12.3;

4. Decrementer dec = new Decrementer();

5. dec.decrement(d);

6. System.out.println(d);

7. }

8. }


9.

10. class Decrementer {

11. public void decrement(double decMe) {

12. decMe = decMe - 1.0;

13, }

14. }


What value is printed out at line 6?

  1. -1.0

  2. 0.0

  3. 11.3

  4. 12.3

Question 74–b

Consider the following class defintion:

public class Demo extends JFrame implements ActionListener{

......


public void actionPerformed(ActionEvent event){

....


}

}

If a JComboBox is used in a class, how should the class be modified to respond to clicks on the JComboBox?



a) public class Demo extends JFrame implements ActionListener

implements ItemListener{

......

public void actionPerformed(ActionEvent event){



....

}

public void itemStateChanged(ActionEvent event){



b) public class Demo extends JFrame implements ItemListener,

ActionListener{

......

public void actionPerformed(ActionEvent event){



....

}

public void itemStateChanged(ItemEvent event){



...

}

}



c) public class Demo extends JFrame implements ActionListener{

......


public void actionPerformed(ActionEvent event){

....


}

public void itemStateChanged(ItemEvent event){

...

}

}



d) public class Demo extends JFrame implements ItemListener,

ActionListener{

......

public void actionPerformed(ActionEvent event){



....

public void itemStateChanged(ItemEvent event){

...

}

}



}

Question 75–abcd

Consider the following code:

1. for (int i = 0; i < 2; i++) {

2. for (int j = 0; j < 3; j++) {

3. if (i == j) {

4. continue;

5. }

6. System.out.println("i = " + i + " j = " + j);



7. }

8. }


Which lines would be part of the output?

  1. i = 0 j = 2

  2. i = 0 j = 1

  3. i = 1 j = 2

  4. i = 1 j = 0

  5. i = 1 j = 1

Question 76–b

Consider the following code:

1. outer: for (int i = 0; i < 2; i++) {

2. for (int j = 0; j < 3; j++) {

3. if (i == j) {

4. continue outer;

5. }

6. System.out.println("i = " + i + " j = " + j);



7. }

8. }


Which lines would be part of the output?

  1. i = 1 j = 1

  2. i = 1 j = 0

  3. i = 0 j = 2

  4. i = 0 j = 1

  5. i = 0 j = 0

Question 77–cde

Consider this class:

1. public class Test1 {

2. public float aMethod(float a, float b) {

3. }

4.

5. }



Which of the following methods would be legal if added (individually) at line 4?

  1. public float aMethod(float c, float d) { }

  2. public float aMethod(float a, float b) { }

  3. public float aMethod(float a, float b, int c) throws Exception { }

  4. public int aMethod(int a, int b) { }

  5. private float aMethod(int a, int b, int c) { }

Question 78–c

__________ describe interactions among objects by depicting the time-ordering of method invocations.



  1. Statechart diagrams

  2. Flowchart diagrams

  3. Sequence diagrams

  4. Class diagrams

Question 79–d

__________ describe the flow of control of an object.



  1. Sequence diagrams

  2. Flowchart diagrams

  3. Class diagrams

  4. Statechart diagrams

Question 80–c

Examine the following code which includes an inner class:

public final class Test4 implements A {

class Inner {

void test() {

if (Test4.this.flag); {

sample();

}

}



}

private boolean flag = false;

public void sample() {

System.out.println(" Sample");

}

public Test4() {



(new Inner()).test();

}

public static void main(String args []) {



new Test4();

}

}



What is the result:

  1. Program produces no output but terminates correctly.

  2. Program does not terminate.

  3. Prints out "Sample"

  4. The program will not compile


Каталог: 2011
2011 -> HƯỚng dẫn viết tiểu luậN, kiểm tra tính đIỂm quá trình môn luật môi trưỜNG
2011 -> Dat viet recovery cứu dữ liệu-hdd services-laptop Nơi duy nhất cứu dữ liệu trên các ổ cứng Server tại Việt Nam ĐC: 1a nguyễn Lâm F3, Q. Bình Thạnh, Tphcm
2011 -> Ubnd tỉnh thừa thiên huế SỞ giáo dục và ĐÀo tạO
2011 -> SỞ TƯ pháp số: 2692 /stp-bttp v/v một số nội dung liên quan đến việc chuyển giao CỘng hòa xã HỘi chủ nghĩa việt nam
2011 -> QUỐc hội nghị quyết số: 24/2008/QH12 CỘng hoà XÃ HỘi chủ nghĩa việt nam
2011 -> NĐ-cp cộng hòa xã HỘi chủ nghĩa việt nam độc lập – Tự do – Hạnh phúc
2011 -> BỘ NỘi vụ CỘng hoà XÃ HỘi chủ nghĩa việt nam
2011 -> Nghị quyết số 49-nq/tw ngàY 02 tháng 6 NĂM 2005 CỦa bộ chính trị VỀ chiến lưỢc cải cách tư pháP ĐẾn năM 2020
2011 -> Ủy ban nhân dân tỉnh bà RỊa vũng tàU
2011 -> Ủy ban nhân dân cộng hòa xã HỘi chủ nghĩa việt nam thành phố HỒ chí minh độc lập Tự do Hạnh phúc

tải về 0.89 Mb.

Chia sẻ với bạn bè của bạn:
1   2   3   4   5   6   7   8




Cơ sở dữ liệu được bảo vệ bởi bản quyền ©hocday.com 2024
được sử dụng cho việc quản lý

    Quê hương