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



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

Question 215–d


using 'super()' in a constructor:

  1. Calls the parent class constructor

  2. Is a method invocation

  3. Must be the first line of code if it is used

  4. All of the others

Question 216–b

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 one large button marked Four in the Centre

  3. A Frame with buttons marked One to four running from the top to bottom

  4. An Error at run time indicating you have not set a LayoutManager

Question 217–a

What can you write at the comment:

//A in the code below so that this program writes the word 'running'

to the standard output?

class RunTest implements Runnable {

public static void main(String[] args) {

RunTest rt = new RunTestQ;

Thread t =new Thread(rt);

//A

}

public void run() {



System.out.println("running");

}

void go() {



start(1);

}

void start(int i) {



}

}


  1. System.out.println("running");

  2. rt.start();

  3. rt.start(1);

  4. rt.go();

Question 218–a

What can be in a super class?



  1. Common instance variables and methods to its subclasses

  2. Only common instance variables of its subclasses

  3. Different instance variables of all the subclasses

  4. Different methods of all the subclasses

Question 219–c

What can contain objects that have a unique key field of String type, if it is required to retrieve the objects using that key field as an index?



  1. Set

  2. List

  3. Map

  4. Enumeration

  5. Collection

Question 220–b

What can you write at the comment:

//A in the code below so that this program writes the word 'running'

to the standard output?

class RunTest implements Runnable {

public static void main(String[] args) {

RunTest rt = new RunTestQ;

Thread t =new Thread(rt);

//A

}

public void run() {



System.out.println("running");

}

void go() {



start(1);

}

void start(int i) {



}

}


  1. rt.start();

  2. System.out.println("running");

  3. rt.go();

  4. rt.start(1);

Question 221–d

What changes are needed to make the following program compile?

2. import java.util.*;

3. class Question {

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

5. String s1 = "abc";

6. String s2 = "def";

7. Vector v = new Vector();

8. v.add(s1);

9. v.add(s2);

10. String s3 = v.elementAt(0) + v.elementAt(1);

11. System.out.println(s3);

12. }

}


  1. Cast v.elementAt(1) to an Object.

  2. Declare Question as public.

  3. Import java.lang.

  4. Cast v.elementAt(0) to a String.

Question 222–a

What code placed after the comment:

// Start For loop

would populate the elements of the array ia[] with values of the variable i?

public class Lin{

public static void main(String argv[]) {

Lin l = new Lin();

l.amethod();

}

public void amethod() {



int ia[] = new int[4];

// Start For loop

{

ia[i]=i;



System.out.println(ia[i]);

}

}



}

  1. for(int i=0; i

  2. for(int i=0; i

  3. for (int i=0; i < ia.length; i++)

  4. for(int i=1; i <4; i++)

Question 223–a

What does the following code do?

String count = "25";

int myCount = Integer.parseInt(count);



  1. Converts the integer 25 into a string with the text 25

  2. Converts a string with the text 25 into an integer with the value 25

  3. Creates an array of 25 int variables

Question 224–b

What does the following program do when it is run with the command:

java Mystery Mighty Mouse

class Mystery {

public static void main(String[] args) {

Changer c = new Changer();

c.method(args);

System.out.println(args[0] + "" + args[1]);

}

static class Changer {



void method(String[] s) {

String temp = s[0];

s[0] = s[1];

s[1] = temp;

}

}

}



  1. This program writes "Mighty Mouse" to the standard output

  2. This program writes "Mouse Mighty" to the standard output

  3. This program causes an ArraylndexOutOfBoundsException to be thrown

  4. This program runs but does not write anything to the standard output

Question 225–b

What does "super.methodA();" do?



  1. call the methodA() defined by its subclass

  2. call the methodA() defined by the superclass of the current class

  3. call the methodA() defined by the class that extends the current class

  4. call the methodA() defined by the current class calling it

Question 226–c

What happens when we try to compile and run the following code?

public class TestQ38 {

public static void main (String[] args){

Object obj = buildTest( 3 ) ;

System.gc();

System.out.println("exiting");

}

public static TestQ38 buildTest(int n ){



TestQ38 t = null ;

for( int i = 0 ; i < n ; i++ ){

t = new TestQ38( i ) ;

}

return t ;



}

String name ;

public TestQ38( int n ){

name = "Number " + n ;

}

public void finalize(){



System.out.print("finalize " + name ) ;

}

}



Assume that garbage collection runs and all elligible objects are collected and finalized.

  1. Before "exiting" is written, 3 messages from finalize will be printed

  2. It does not compile due to incorrect signature of the finalize method

  3. Before "exiting" is written, 2 messages from finalize will be printed

  4. It compiles but no text is written when it runs due to incorrect signature of the finalize method

Question 227–d

What happens when you attempt to compile and run the following code?

import java.util.*;

public class RapCollect {

public static void main(String argv[]){

HashMap hm = new HashMap();

hm.put("one", new Integer(1));

hm.put("two", new Integer(2));

hm.put("three",new Integer(3));

Set set = hm.keySet();

Iterator it = set.iterator();

while (it.hasNext()){

Integer iw = it.next();

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

}

}


  1. Compile-time error; fault with arguments with put method.

  2. Compilation is fine but an error occurs at runtime.

  3. Compile-time error; Set is an interface and cannot be instantiated

  4. Compile-time error; code error within the while loop.

  5. Compile-time error; HashMap has no keySet method.

Question 228–d

What happens when you attempt to compile and run these two files in the same directory?

//File P1.java

package MyPackage;

class P1{

void afancymethod(){

System.out.println("What a fancy method");

}

}



//File P2.java

public class P2 extends P1{

afancymethod();

}


  1. Both compile but P2 has an error at run time

  2. Both compile and P2 outputs "What a fancy method" when run

  3. Neither will compile2

  4. P1 compiles cleanly but P2 has an error at compile time

Question 229–d

What happens when you try to compile and run the following program?

class Mystery {

String s;

public static void main(String[] args) {

Mystery m = new Mystery();

m.go ();

}

void Mystery() {



s = "constructor";

}

void go() {



System.out.println(s);

}

}



  1. this code will not compile

  2. this code runs but nothing appears in the standard output

  3. this code runs and "constructor" in the standard output

  4. this code runs and writes "null" in the standard output

  5. this code compiles but throws an exception at runtime

Question 230–d

What is a linked list?



  1. A method for searching through a set of data.

  2. A method of keeping computer code organized.

  3. It is used to complete the same action multiple times.

  4. A type of data storage

Question 231–c

What is displayed on the console when running the following program?

class Test {

public static void main(String[] args) {

try {

method();



System.out.println("After the method call");

}

catch (NumberFormatException ex) {



System.out.println("NumberFormatException");

}

catch (RuntimeException ex) {



System.out.println("RuntimeException");

}

}



static void method() {

Integer.parseInt(5.6); // Cause a NumberFormatException

int i = 0;

int y = 2 / i;

System.out.println("Welcome to Java");

}

}



  1. The program displays RuntimeException.

  2. The program displays NumberFormatException followed by RuntimeException.

  3. The program displays NumberFormatException.

  4. The program displays NumberFormatException followed by After the method call.

  5. The program has a compilation error.

Question 232–b

What is displayed on the console when running the following program?

class Test {

public static void main(String[] args) {

try {

method();



System.out.println("After the method call");

}

catch (RuntimeException ex) {



System.out.println("RuntimeException");

}

catch (Exception ex) {



System.out.println("Exception");

}

}



static void method() throws Exception {

try {


Integer.parseInt(5.6); // Cause a NumberFormatException

int i = 0;

int y = 2 / i;

System.out.println("Welcome to Java");

}

catch (NumberFormatException ex) {



System.out.println("NumberFormatException");

throw ex;

}

catch (RuntimeException ex) {



System.out.println("RuntimeException");

}

}



}

  1. The program displays NumberFormatException followed by After the method call.

  2. The program displays NumberFormatException followed by RuntimeException.

  3. The program displays NumberFormatException twice.

  4. The program has a compilation error.

Question 233–a

What is displayed on the console when running the following program?

class Test {

public static void main(String[] args) {

try {

method();



System.out.println("After the method call");

}

catch (RuntimeException ex) {



System.out.println("RuntimeException");

}

catch (Exception ex) {



System.out.println("Exception");

}

}



static void method() throws Exception {

try {


Integer.parseInt(5.6); // Cause a NumberFormatException

int i = 0;

int y = 2 / i;

System.out.println("Welcome to Java");

}

catch (RuntimeException ex) {



System.out.println("RuntimeException");

}

catch (Exception ex) {



System.out.println("Exception");

}

}



}

  1. The program displays RuntimeException followed by After the method call.

  2. The program displays Exception followed by RuntimeException.

  3. The program displays RuntimeException twice.

  4. The program displays Exception twice.

  5. The program has a compilation error.

Question 234–d

What is displayed on the console when running the following program?

class Test {

public static void main(String[] args) {

try {

System.out.println("Welcome to Java");



int i = 0;

double y = 2.0 / i;

System.out.println("Welcome to HTML");

}

finally {



System.out.println("The finally clause is executed");

}

}



}

  1. Welcome to Java.

  2. None of the other answers

  3. Welcome to Java followed by The finally clause is executed in the next line.

  4. The program displays three lines: Welcome to Java, Welcome to HTML, The finally clause is executed.

Question 235–d

What is displayed on the console when running the following program?

class Test {

public static void main(String[] args) {

try {

System.out.println("Welcome to Java");



int i = 0;

int y = 2/i;

System.out.println("Welcome to HTML");

}

finally {



System.out.println("The finally clause is executed");

}

}



}

  1. Welcome to Java.

  2. The program displays three lines: Welcome to Java, Welcome to HTML, The finally clause is executed.

  3. None of the other answers

  4. Welcome to Java followed by The finally clause is executed in the next line.

Question 236–b

What is displayed on the console when running the following program?

class Test {

public static void main(String[] args) {

try {

System.out.println("Welcome to Java");



int i = 0;

int y = 2/i;

System.out.println("Welcome to Java");

}

finally {



System.out.println("End of the block");

}

System.out.println("End of the block");



}

}


  1. The program displays Welcome to Java three times followed by End of the block.

  2. The program displays Welcome to Java and End of the block, and then terminates because of an unhandled exception.

  3. The program displays Welcome to Java two times followed by End of the block two times.

  4. The program displays Welcome to Java two times followed by End of the block.

Question 237–c

What is displayed on the console when running the following program?

class Test {

public static void main(String[] args) {

try {

System.out.println("Welcome to Java");



int i = 0;

int y = 2/i;

System.out.println("Welcome to Java");

}

catch (RuntimeException ex) {



System.out.println("Welcome to Java");

}

finally {



System.out.println("End of the block");

}

}



}

  1. The program displays Welcome to Java three times followed by End of the block.

  2. The program displays Welcome to Java two times.

  3. The program displays Welcome to Java two times followed by End of the block.

  4. The program displays Welcome to Java three times.

Question 238–d

What is printed to standard output?

1. Class Misc3 {

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

3. final double Mtons = 3.33;

4. NewMoon moon = new NewMoon();

5. moon.Volcano();

6. moon.Crater(Mtons);

7. }

8. }


9. class Planet {

10. final double Mtons = 7.77;

11. final void Crater(final double Mtons) {

12. System.out.println("Crater loss "+Mtons+" Mtons");

13. }

14. }


15. class NewMoon extends Planet {

16. final double Mtons = 5.55;



  1. void Volcano(){

18. Crater(Mtons);

19. }


20. }

  1. Code fails to compile at lines 10 and 16 because Mtons has been declared as a final variable and cannot be changed

  2. Code fails to compile at line 6 because an instance of NewMoon does not contain the method Crater()

  3. Code fails to compile at line 18 because Crater is final and cannot be extended

  4. Crater loss 5.55 Mtons, Crater loss 3.33 Mtons

  5. Crater loss 3.33 Mtons

Question 239–c

What is printed to standard output?

1. class Misc4 {

2. final static double MTons = 3.33;

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

4. NewMoon moon = new NewMoon();

5. moon.Volcano();

6. moon.Crater(MTons);

7. }

8. }


9. class Planet {

10. final double MTons = 7.77;

11. final void Crater(final double MTons) {

12. System.out.println("Crater loss "+MTons+" MTons");

13. }

14. }


15. class NewMoon extends Planet {

16. final double MTons = 5.55;



  1. void Volcano(){

18. Crater(MTons);

19. }}


  1. Crater loss 3.33 Mtons

  2. Code fails to compile at line 6 because an instance of NewMoon does not contain the method Crater()

  3. Crater loss 5.55 Mtons, Crater loss 3.33 Mtons

  4. Code fails to compile at line 18 because Crater is final and cannot be extended

  5. Code fails to compile at lines 10 and 16 because Mtons has been declared as a static final variable that cannot be changed

Question 240–d

What is printed to standard output?

import java.io.*;

class Misc1 {

int x,y;

public static void main(String args[]){

Misc1 M1 = new Misc1();

M1.Normal();

}

void Normal()



{

x = 5; y = 3;

System.out.print( " ( " + x + ", " + y + " ) " );

swap( x, y );

System.out.print( " ( " + x + ", " + y + " ) " );

}

void swap( int p, int q )



{ int temp;

temp = p;

p = q;

q = temp;



x = p;

y = q;


System.out.print( " ( " + x + ", " + y + " ) " );

}

}



  1. (5, 3) (3, 5) (5, 3)

  2. (5,3) (5,3) (3, 5)

  3. (5, 3) (5, 3) (5, 3)

  4. (5, 3) (3, 5) (3, 5)

  5. (3,5) (3, 5) (3,5)

Question 241–b

What is the best suitable relationship between Company and Employee?



  1. Association

  2. Aggregation

  3. None

  4. Inheritance

Question 242–b

What is the correct order of node visiting for post-order traversal of the following tree?





  1. GDBAEFC

  2. GDBEFCA

  3. BDGECFA

  4. EFCGDBA

Question 243–e

What is the default layout manager for a Frame container and Window container?



  1. GridLayout

  2. Null

  3. CardLayout

  4. FlowLayout

  5. BorderLayout

  6. GridBagLayout

Question 244–a

What is the default layout manager for a Panel container?



  1. FlowLayout

  2. BorderLayout

  3. CardLayout

  4. GridLayout

  5. GridBagLayout

Question 245–d

What is the difference between the components of an abstract class and an interface?



  1. An abstract class can have non-abstract methods but all methods in an interface must be abstract. However, both of them can have instance variables

  2. An interface is just a special case of an abstract class. It has instance variables, abstract methods and non-abstarct methods.

  3. So there is no difference.

  4. An abstract class can have instance variables, but an interface cannot have instance variables. However, all methods in both an abstact class and an interface should be abstract

  5. An abstract class can have instance variables and some non-abstract methods. But an interface cannot have instance variables and all methods must be abstract

Question 246–b

What is the effect of adding the sixth element to a vector created in the following manner:

new Vector(5, 10);


  1. The vector grows in size to a capacity of 10 elements

  2. The vector grows in size to a capacity of 15 elements

  3. An IndexOutOfBounds exception is raised.

  4. Nothing, the vector will have grown when the fifth element was added

Question 247–d

What is the effect of issuing a wait() method on an object



  1. An exception will be raised

  2. The object issuing the call to wait() will be automatically synchronized with any other objects using the receiving object.

  3. If a notify() method has already been sent to that object then it has no effect

  4. The object issuing the call to wait() will halt until another object sends a notify() or notifyAll() method

Question 248–d

What is the first step to take to run a thread?



  1. Use the makeThread method of the System class.

  2. Write a class that implements the Thread interface.

  3. Use the ThreadFactory class to create a Thread.

  4. Write a class that extends the Thread class

Question 249–b

What is the meaning of the reserved word "this" in Java?



  1. a number

  2. a variable that references the same object that the method is already executing in the context of

  3. the current class

  4. the current method

Question 250–d

What is the output displayed by the following program?

class Question {

public static void main(String[] args) {

String s1="ab";

String s2="abcd";

String s3="cd";

String s4=s1 + s3;

s1=s4;

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



}

}


  1. true false

  2. false false

  3. true true

  4. false true

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