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



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

Question 251–d

What is the output of running A?

public class A extends B {

int x = 1;

public static void main(String[] args) {

System.out.print(new A().x);

System.out.print(new B().x);

}

}



class B {

int x = 5;

}


  1. 51

  2. 11

  3. 55

  4. 15

Question 252–a

What is the output of running class C?

class A {

public A() {

System.out.println(

"The default constructor of A is invoked");

}

}

class B extends A {



public B() {

System.out.println(

"The default constructor of B is invoked");

}

}



public class C {

public static void main(String[] args) {

B b = new B();

}

}



a) "The default constructor of A is invoked"

"The default constructor of B is invoked"

"The default constructor of B is invoked"

b) none


c) "The default constructor of A is invoked"

"The default constructor of B is invoked"

"The default constructor of A is invoked"

Question 253–d

What is the output of running class Test.

public class Test {

public static void main(String[] args) {

new Circle9();

}

}



public abstract class GeometricObject {

protected GeometricObject() {

System.out.print("A");

}

protected GeometricObject(String color, boolean filled) {



System.out.print("B");

}

}



public class Circle9 extends GeometricObject {

/** Default constructor */

public Circle9() {

this(1.0);

System.out.print("C");

}

/** Construct circle with a specified radius */



public Circle9(double radius) {

this(radius, "white", false);

System.out.print("D");

}

/** Construct a circle with specified radius, filled, and color */



public Circle9(double radius, String color, boolean filled) {

super(color, filled);

System.out.print("E");

}

}



  1. AEDC

  2. CBAE

  3. ABCD

  4. BEDC

  5. BACD

Question 254–c

What is the output of the following code?

1 int i = 45678;

2 int j = ~i;

3

4 System.out.println(j);



  1. Compilation error at line 2. ~ operator applicable to boolean values only

  2. Prints 45677

  3. Prints –45679

  4. Prints -45677

Question 255–c

What is the output of the following code?

class X {

public static void main (String x [ ]) {

B myB = new B( );

if (myB instanceof C)

System.out.println ("TRUE");

else


System.out.println ("FALSE");

}//main


}//class

  1. FALSE

  2. TRUE FALSE

  3. doesn't compile

  4. no output to screen

  5. TRUE

Question 256–c

What is the output of the following code?

int m;

for (int j = 2, m = 1; j > 0; j--) {



for (int k = 2; ; k--) {

if (k == 1) break;

System.out.println (j+" "+m+" "+k);

}

}



  1. 212, 211, 112, 111

  2. 211, 112, 111

  3. none of the other answers (or code doesn't compile)

  4. 212, 211, 210, 112, 111, 110

  5. 212, 112

Question 257–d

What is the output of the following code:

public class Test {

public static void main(String[] args) {

Object o1 = new Object();

Object o2 = new Object();

System.out.print((o1 == o2) + " " + (o1.equals(o2)));

}

}



  1. true true

  2. true false

  3. false true

  4. false false

Question 258–a

What is the output of the following code:

public class Test {

public static void main(String[] args) {

String s1 = new String("Java");

String s2 = new String("Java");

System.out.print((s1 == s2) + " " + (s1.equals(s2)));

}

}



  1. false true

  2. true true

  3. false false

  4. true false

Question 259–a

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 = s1;

s1 += "and Welcome to HTML";

if (s1 == s2)

System.out.println("s1 and s2 reference to the same String object");

else


System.out.println("s1 and s2 reference to different String objects");

}

}



  1. s1 and s2 reference to different String objects

  2. s1 and s2 reference to the same String object

Question 260–a

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 = s1.toUpperCase();

if (s1 == s2)

System.out.println("s1 and s2 reference to the same String object");

else if (s1.equals(s2))

System.out.println("s1 and s2 have the same contents");

else

System.out.println("s1 and s2 have different contents");



}

}


  1. s1 and s2 have different contents

  2. s1 and s2 reference to the same String object B. s1 and s2 have the same contents

Question 261–d

What is the output of the following code segment?

int num = 4;

int power = 3;

int product = 0;

int i = 0;

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

product *= num;

System.out.println(product);


  1. 64

  2. 16

  3. 256

  4. 0

Question 262–a

What is the output of the following code snippet?

public static void main (String x[ ]) {

int a = 4;

a ^= 2;

System.out.println (a);



}

  1. The code prints out 6

  2. The code doesn't compile because there is no shortcut expression ^=

  3. The code prints out 0

  4. The code doesn't compile because you cannot print a variable that has been ^'d

  5. The code prints out 4

Question 263–a

What is the output of the following program?

33. import java.util.*;

34. class Question {

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

36. HashSet set = new HashSet();

37. String s1 = "abc";

38. String s2 = "def";

39. String s3 = "";

40. set.add(s1);

41. set.add(s2);

42. set.add(s1);

43. set.add(s2);

44. Iterator i = set.iterator();

45. while(i.hasNext()){

46. s3 += (String) i.next();

47. }

48. System.out.println(s3);



49. }

}


  1. defabc

  2. fedcbafedcba

  3. abcdefabcdef

  4. defabcdefabc

Question 264–b

What is the output of the following program?

import java.util.*;

public class Question {

public static void main(String args[]){

String strings[] = {"skis","bobsled",

"figure skates"};

List list = Arrays.asList(strings);

displayList(list);

}

static void displayList(List list) {



ListIterator i = list.listIterator(0);

while(i.hasNext()){

Object o = i.next();

if(o == null) System.out.println("null");

else System.out.println(o.toString());

}

}



}

a) bobsled

figure skates

skis


b) skis

bobsled


figure skates

c) null


d) A compiler error

Question 265–a

What is the output of the following program?

public class Test {

public static void main(String[] args) {

new A();

}

{



System.out.print("Z");

}

}



class A extends B {

A() {


System.out.print("A");

}

{



System.out.print("X");

}

}



class B {

B() {


System.out.print("B");

}

{



System.out.print("Y");

}

}



  1. YBXA

  2. BXAY

  3. XYAB

  4. YBXAZ

Question 266–d

What is the output of the following program?

public class Test extends Object {

public static void main(String[] args) {

Test test = new Test();

}

public Test() {



System.out.print("A");

}

{



System.out.print("B");

}

static {



System.out.print("C");

}

}



  1. BAC

  2. ABC

  3. ACB

  4. CBA

  5. CAB

Question 267–c

What is the output of the following program when it is invoked using the command line java Test: what do you say?

class Test {

public static void main(String[] args) {

System.out.println(args[2]);

}

}



  1. what

  2. say

  3. you

  4. do

Question 268–d

What is the path from node C to I?





  1. C, H, G, I

  2. C, G, E, I

  3. C, B, H, I

  4. C, E, H, I

  5. C, D,E, I

Question 269–b

What is the printout for the first statement in the main method?

public class Foo {

static int i = 0;

static int j = 0;

public static void main(String[] args) {

int i = 2;

int k = 3;

{

int j = 3;



System.out.println("i + j is " + i + j);

}

k = i + j;



System.out.println("k is " + k);

System.out.println("j is " + j);

}

}


  1. i + j is 22

  2. i + j is 23

  3. i + j is 6

  4. i + j is 5

Question 270–a

What is the printout of the second println statement in the main method?

public class Foo {

int i;


static int s;

public static void main(String[] args) {

Foo f1 = new Foo();

System.out.println("f1.i is " + f1.i + " f1.s is " + f1.s);

Foo f2 = new Foo();

System.out.println("f2.i is " + f2.i + " f2.s is " + f2.s);

Foo f3 = new Foo();

System.out.println("f3.i is " + f3.i + " f3.s is " + f3.s);

}

public Foo() {



i++;

s++;


}

}


  1. f2.i is 1 f2.s is 2

  2. f2.i is 2 f2.s is 1

  3. f2.i is 2 f2.s is 2

  4. f2.i is 1 f2.s is 1

Question 271–d

What is the printout for the third statement in the main method?

public class Foo {

static int i = 0;

static int j = 0;

public static void main(String[] args) {

int i = 2;

int k = 3;

{

int j = 3;



System.out.println("i + j is " + i + j);

}

k = i + j;



System.out.println("k is " + k);

System.out.println("j is " + j);

}

}


  1. j is 1

  2. j is 3

  3. j is 2

  4. j is 0

Question 272–c

What is the purpose of count < phrase.length in the following code?

int[] letterCount = new int[26];

for (int count = 0; count < phrase.length; count++) {

String current = phrase[count];

char[] letters = current.toCharArray();

}


  1. sets the count variable to the number of letters in a phrase

  2. determines the number of letters in a phrase

  3. makes the loop stop when the end of the phrase array is reached

Question 273–c

What is the purpose of the getSeconds() method in this class?

public class Virus {

private int newSeconds = 86;

public int getSeconds() {

return newSeconds;

}


  1. it changes the value of newSeconds

  2. there is not enough code to tell what its purpose is

  3. it makes the value newSeconds available to other objects

Question 274–b

What is the result of compiling and running the following program.

Select the one correct answer.

class test {

public static void main(String args[]) {

char ch;


String test2 = "abcd";

String test = new String("abcd");

if(test.equals(test2)) {

if(test == test2)

ch = test.charAt(0);

else


ch = test.charAt(1);

}

else {



if(test == test2)

ch = test.charAt(2);

else

ch = test.charAt(3);



}

System.out.println(ch);

}

}


  1. 'c'

  2. 'b'

  3. 'a'

  4. 'd'

Question 275–e

What is the result of executing the following Java class:

import java.awt.*;

public class FrameTest extends Frame {

public FrameTest() {

add (new Button("First"));

add (new Button("Second"));

add (new Button("Third"));

pack();

setVisible(true);

}

public static void main(String args []) {



new FrameTest();

}

}



Select from the following options:

  1. Nothing happens.

  2. A runtime exception is generated (no layout manager specified).

  3. Three buttons are displayed across a window.

  4. Only the "second" button is displayed.

  5. Only the "third" button is displayed.

  6. Only the "first" button is displayed.

Question 276–b

What is the result of the following code?

class X {

int myVar;

X ( ) {

System.out.println (myVar);



}

}//--------------------------------------

class Driver {

public static void main(String x[]) {

X myX= new X();

}

}//---------------------------------------



  1. the code compiles but will the give a Runtime Exception

  2. the code compiles and prints out 0

  3. The code doesn't compile because the attribute myVar was never initialized

  4. The code doesn't compile because print statements aren't allowed in the constructor

Question 277–a

What is the results of the code below?

byte b = 6;

byte c = 201;

System.out.println ("B + C =" + (b+c));


  1. The code does not compile

  2. The code prints out "B + C =-41"

  3. The code prints out "B + C =207"

Question 278–c

What is the result of the following program?

class Question {

public static void main(String[] args) {

int i = 7;

int j = 8;

int n = (i | j) % (i j);

System.out.print(n);

}

}


  1. 15

  2. 0

  3. An ArithmeticException is thrown.

  4. -15

Question 279–b

What is the value displayed by the following program?

class Question {

public static void main(String[] args) {

int x=0;

boolean b1, b2, b3, b4;

b1=b2=b3=b4=true;

x=(b1 | b2 b3 ^ b4) ? x++ : --x;

System.out.println(x);

}

}



  1. 2

  2. 0

  3. –1

  4. –2

  5. 3

  6. 1

Question 280–d

What is the value of data after execution of the following code?

JTextField [] data = new JTextField[10];

for(int i=0; i

data[i] = new JTextField(20);

}


  1. data = null

  2. data[i] = null

  3. data[i] stores a reference to an array object

  4. data[i] stores a reference to a JTextField

Question 281

What is the value of myCount.count displayed?

public class Test {

public static void main(String[] args) {

Count myCount = new Count();

int times = 0;

for (int i=0; i<100; i++)

increment(myCount, times);

System.out.println(

"myCount.count = " + myCount.count);

System.out.println("times = "+ times);

}

public static void increment(Count c, int times) {



c.count++;

times++;


}

}

class Count {



int count;

Count(int c) {

count = c;

}

Count() {



count = 1;

}

}



  1. 98

  2. 101

  3. 100

  4. 99

Question 282–d

What is the value of data after execution of the following code?

JTextField [] data = new JTextField[10];

for(int i=0; i

data[i] = new JTextField(20);

}


  1. data[i] stores a reference to an array object

  2. data[i] = null

  3. data = null

  4. data[i] stores a reference to a JTextField

Question 283–c

What is the value of the variable age when it is displayed in the following method?

public static void main(String args[])

{

int age=30;



float cost = age*1.5;

System.out.println("Age is "+age+". Cost is "+cost);

}


  1. 45.0

  2. 30.0

  3. 30

  4. 45

Question 284–d

What is the value of times displayed?

public class Test {

public static void main(String[] args) {

Count myCount = new Count();

int times = 0;

for (int i=0; i<100; i++)

increment(myCount, times);

System.out.println(

"myCount.count = " + myCount.count);

System.out.println("times = "+ times);

}

public static void increment(Count c, int times) {



c.count++;

times++;


}

}

class Count {



int count;

Count(int c) {

count = c;

}

Count() {



count = 1;

}

}



  1. 100

  2. 101

  3. 98

  4. 0

Question 285–a

What is the value of y after execution of the following statements?

int x = 5;

int y = 4;

y = x++;


  1. 5

  2. 6

  3. 7

  4. 4

Question 286–d

What is written to the standard output as the result of executing the following statements?

Boolean bl = new Boolean(true);

Boolean b2 = new Boolean(true);

Object obj 1 = (Obj ect) b1;

Object obj2 = (Object) b2;

if(objl ==obj2)

if (obj 1.equals(obj2))

System.out.println("a");

else


System.out.println("b");

else


if (obj 1 .equals(obj2))

System.out.println("c");

else

System.out.println("d");



Select the one right answer.

  1. b

  2. a

  3. d

  4. c

Question 287–a

What is written to the standard output given the following statement:

System.out.println(4 7);


  1. 4

  2. 7

  3. 5

  4. 0

  5. 6

Question 288–bc

What is wrong with the following code?

final class First {

private int a = 1;

intb=2;

}

class Second extends First {



public void method() {

System.out.println(a + b);

}

}


  1. You cannot invoke println() without passing it a String

  2. Second cannot extend First

  3. Since a is private, no classes other than First can access it

  4. final is not a valid keyword for a class

Question 289–c

What is wrong with the following code segment?

int [] data = new int[9];

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

data[i] = i;

}


  1. nothing wrong

  2. data[i] = i; should be data = i;

  3. i<=9 should be i<9

  4. int [] data = new int[9] should be int [] data;

Question 290–d

What keyword can you use to refer to the methods and variables of a superclass?



  1. this

  2. call

  3. get

  4. super

Question 291–c

What modifier should you use on a class so that a class in the same package can access it but a class in a different package cannot access it?



  1. Protected

  2. Private

  3. Use the default modifier.

  4. public

Question 292–a

What modifier should you use on the members of a class so that they are not accessible to another class in a different package, but are accessible to any subclasses in any package?



  1. protected

  2. public

  3. Use the default modifie

  4. private

Question 293–ac

What must be true for the RuriHandler class so that instances of RunHandler can be used as written in the code below:

class Test {

public static void main(String[] args) {

Thread t = new Thread(new RunHandler());

t.start();

}

}


  1. RunHandler must provide a run() method declared as public and returning void.

  2. RunHandler must extend the Thread class.

  3. RunHandler must implement the java.lang.Runnable interface.

  4. RunHandler must provide an init() method.

Question 294–bc

What order can you place the following pieces of a source file in so that the source file will compile without errors or warnings?

//A

import j ava.applet. *;



//B

class Helper {

}

//C


package myclasses;

//D


public class MyApplet extends java.applet.Applet {

}


  1. A, B, C, D

  2. C, A, B, D

  3. C, A, D, B

  4. A, C, B, D

  5. C, B, A, D

Question 295–b

What output does the following program display?

14. import java.util.*;

15. class Question {

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

17. String s1 = "abc";

18. String s2 = "def";

19. Stack stack = new Stack();

20. stack.push(s1);

21. stack.push(s2);

22. try {

23. String s3 = (String) stack.pop() + (String) stack.pop();

24. System.out.println(s3);

25. }catch(EmptyStackException ex){

26. }

27. }


}

  1. abcabc

  2. defabc

  3. abcdef

  4. defdef


Каталог: 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