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



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

UPDATED

417. In order to determine the type that a polymorphic variable refers to, the decision is made



  1. by the operating system when the program is loaded into memory

  2. by the programmer at the time the program is written

  3. by the compiler at compile time

  4. by the user at run time

  5. by the Java run-time environment at run time

418 . 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; c. Base.oak = 22;

  2. oak = 50.1; d. oak = 33;

419.Which of the following is the correct way to declare a native method?

  1. public native void method( ); c. public void method ( ) native;

  2. public void method ( ); d. native public void method( );

420 . Which of these statements are true? Select all valid answers.

  1. A constructor can access the non-static members of a class

  2. All classes must explicitly define a constructor.   

  3. A constructor can be declared private.

  4. A constructor must initialize all the member variables of a class.

  5. A constructor can declare a return value.

421. Which of the following are you able to do when overloading a method?

  1. change the method name d. change the return type

  2. change the parameters e. make it more public or private

  3. change the exceptions thrown

422. Assume class B extends class A. They are defined as follows:


class A {
int x = 10;
public void addX(){
x = x +1;
}
} // end of class A

class B extends A{


int y = 5;
public B(){
super.addX();
x = x+1;
y = y+100;
}
}//end of class B

Assume bbb is a reference to B object, that is, "B bbb = new B(); "What is the value of x and y in bbb?



  1. x = 10, y = 5 c. x = 12, y = 105

  2. x = 11, y = 105 d. x = 0, y = 105

423. What is the output of the following code?
class X {
public static void main (String x [ ]) {
   B myB = new B( );
   if (myB instanceof D)
    System.out.println ("TRUE");
   else
    System.out.println ("FALSE");
}//main
}//classa

  1. TRUE FALSE c. no output to screen

  2. doesn't compile d. FALSE e. TRUE

424. What results from the following fragment of code?
1. int x = 1;
2. String [] names = { "Fred", "Jim", "Sheila" };
3. names[--x] += ".";
4. for (int i = 0; i < names.length; i++) {
5. System.out.println(names[i]);
6. }

  1. The output includes Jim. with a trailing period.

  2. An ArrayIndexOutOfBoundsException is thrown.

  3. The output includes Fred. with a trailing period.

  4. The output includes Sheila. with a trailing period.

  5. None of the outputs show a trailing period.

425. A derived class has access to all of the methods of the parent class, but only the protected or public instance data of the parent class.

False b. True


426. java.lang.Object does not contain which method?

  1. It contains none of these c. toString()

  2. equals()    d. exit()   

427. What statement can you use to refer to the methods and variables of a superclass?

  1. This b. super c. call

428. A class Car and its subclass Yugo both have a method run() which was written by the programmer as part of the class definition. If junker refers to an object of type Yugo, what will the following code do?
junker.show();

  1. The show() method defined in Car will be called.

  2. Overloading will be used to pick which run() is called

  3. The compiler will complain that run() has been defined twice

  4. The show() method defined in Yugo will be called.

429. Given:
1 class Bool {
2 static boolean b;
3 public static void main(String [] args) {
4 int x=0;
5 if (b ) {
6 x=1;
7 }
8 else if (b = false) {
9 x=2;
10 }
11 else if (b) {
12 x=3;
13 }
14 else {
15 x=4;
16 }
17 System.out.println("x = " + x);
18 }
19 }
What is the result?

  1. x=2 b. x=4 c. x=3

d. Compilation fails   e .   X=1 f. x=0

421. You are given a class hierarchy with an instance of the class Dog. The class Dog is a child of mammal and the class Mammal is a child of the class Vertebrate. The class Vertebrate has a method called move which prints out the string "move". The class mammal overrides this method and prints out the string "walks". The class Dog overrides this method and prints out the string "walks on paws". Given an instance of the class Dog,. how can you access the ancestor method move in Vertebrate so it prints out the string "move";



  1. none of the above c. d.parent().parent().move();

  2. d.move(); d. d.super().super().move();

422. What is the default layout manager for a Panel container?

  1. GridLayout c. BorderLayout e. GridBagLayout

  2. CardLayout d. FlowLayout

423. Select ALL errors in the following application progam:
public class B{
private int x;
public void main(String [] arguments){
x = 10;
}
}

  1. this program is correct, no errors b. arguments should be renamed to args

  2. method main is not defined static d. x can not be accessed directly in the main method

424. The instruction super( ); does which of the following?a

  1. calls the method super as defined in java.lang

  2. calls the method super as defined in the current class’ parent class

  3. calls the constructor as defined in the current class

  4. calls the constructor as defined in the current class’ parent class

  5. calls the method super as defined in the current class

425. Which one statement is true about this code?
1. class HasStatic
2. {
3. private static int x = 100;
4.
5. public static void main(String args[])
6. {
7. HasStatic hs1 = new HasStatic();
8. hs1.x++;
9. HasStatic hs2 = new HasStatic();
10. hs2.x++;
11. hs1 = new HasStatic();
12. hs1.x++;
13. HasStatic.x++;
14. System.out.println("x = " + x);
15. }
16. }

  1. The program compiles, and the output is x = 104.

  2. Line 13 will not compile, because it is a static reference to a private variable.

  3. The program compiles, and the output is x = 103.

  4. Line 8 will not compile, because it is a static reference to a private variable.

  5. The program compiles, and the output is x = 102.

426. Select ALL statements that are true about inheritance in Java:

  1. Java allows single inheritance

  2. Java allows multiple inheritance

  3. Constructors are inherited by a subclass

  4. Constructors are not inherited by a subclass

427. 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);
}
a. 45.0 b. 30.0 c. 30 d. 45

428. What type of inheritance does Java have?



  1. multiple inheritance c. single inheritance

  2. class inheritance d .double inheritance

429. How would you describe the relation between java.awt.Frame and java.awt.Container?

  1. "has a" c. modifys

  2. "is a"    d. implements   

430. Which of the statements below are true? (Choose none, some, or all.)

  1. When an instance of File is garbage collected, the corresponding
    file on the local file system is deleted.

  2. None of the above.

  3. When you construct an instance of File, if the corresponding file
    does not exist on the local file system, one will be created.


  4. When you construct an instance of File, if you do not use the filenaming semantics of the local machine, the constructor will throw
    an IOException.


431. Which one statement is true about this application?
1. class StaticStuff
2 {
3. static int x = 10;
4.
5. static { x += 5; }
6.
7. public static void main(String args[])
8. {
9. System.out.println("x = " + x);
10. }
11.
12. static { x /= 5; }
13. }

  1. The code compiles, and execution produces the output x = 3.

  2. Line 12 will not compile, because you can only have one static initializer.

  3. Lines 5 and 12 will not compile, because the method names and return types are missing.

  4. The code compiles, and execution produces the output x = 10.

  5. The code compiles, and execution produces the output x = 15.

432. I want a method of class Y to have access to a variable inside class X. If Y doesn’t extend X, what visibility must I give to that variable:

  1. Protected c. static e. private

  2. none of the above d. public

433. Which of the following are subclasses allowed to do to methods they are overriding from the parent class?

  1. make the more public ?

  2. throw new kinds of unchecked Exceptions

  3. make them more private

  4. change the return type

  5. throw new kinds of checked Exceptions

434. 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);
}}
a. 'd' b. 'b' c. 'a' d. 'c'

435. Which of the following code fragments would compile successfully and print "Equal" when run? (Choose one or more.)



  1. String x = "100";
    String y = "100";if (x == y) { System.out.println("Equal");}

  2. int x = 100; Integer y = new Integer(100);
    if (x == y) { System.out.println("Equal");}

  3. int x = 100; float y = 100.0F;
    if (x == y){ System.out.println("Equal");}

  4. Integer x = new Integer(100);
    Integer y = new Integer(100);
    if (x == y) { System.out.println("Equal");}

  5. String x = new String("100");
    String y = new String("100");
    if (x == y) { System.out.println("Equal");}

437. 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( data[10], lbl);

  3. methodA(data[], lbl);

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

What will happen if you compile/run the following code?
1 public class Q11
2 {
3 static String str1 = "main method with String[] args";
4 static String str2 = "main method with int[] args";
5
6 public static void main(String[] args)
7 {
8 System.out.println(str1);
9 }
10
11 public static void main(int[] args)
12 {
13 System.out.println(str2);
14 }
15 }

  1. Duplicate method main(), compilation error at line 11

  2. Prints "main method with main String[] args"

  3. Prints "main method with main int[] args"

  4. uplicate method main(), compilation error at line 6

438. Which of the following is not a valid Java identifier?

  1. m_x c. my Value

  2. $_AAA1 d. width

439. Which is the best way to receive events when a Button component is activated (pressed)?

  1. Subclass ActionAdapter and override the actionPerformed() method. Then, add an instance of the subclass as a listener to the Button component by invoking addActionListener().

  2. Create an implementation of ButtonListener and add it as a listener to the Button component by invoking addButtonListener().

  3. Subclass MouseAdapter and override the actionPerformed() method. Then, add an instance of the subclass as a listener to the Button component by invoking addMouseListener().

  4. Create an implementation of ActionListener and add it as a listener to the Button component by invoking addActionListener().

440. A class Car and its subclass Yugo both have a method run() which was written by the programmer as part of the class definition. If junker refers to an object of type Yugo, what will the following code do?

junker.show();



  1. The compiler will complain that run() has been defined twice

  2. The show() method defined in Yugo will be called.

  3. Overloading will be used to pick which run() is called

  4. The show() method defined in Car will be called.

441. What objects are created when the following program is executed?
public class AAA{
public static void main(String [] args){
System.out.println("hello");
}
}

  1. two objects of AAA c. an object of AAA

  2. an object of AAA and an object of main d. none

442. 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 = 0 j = 1 c. i = 0 j = 0 e. i = 0 j = 2

  2. i = 1 j = 0 d. i = 1 j = 1

443. A class design requires that a particular member variable must be accessible for direct access by any subclasses of this class, but otherwise not by classes which are not members of the same package. What should be done to achieve this?

  1. The variable should be marked private and an accessor method provided.

  2. The variable should be marked private.

  3. The variable should be marked public.

  4. The variable should be marked protected.

  5. The variable should have no special access modifier.

444. Assume there is a class X with a method 'do()'. If the access modifier for 'do()' is 'protected' where is this method visible?

  1. It is visible to all classes to which X is visible   

  2. It is visible within 'X' only.   

  3. It is not visible anywhere

  4. It is visible to all classes that are friendly to or derived from class X

445. Given:
1. public abstract class Prod {
2. public abstract void prmth1();
3. public static void prmth2() {
4. int mth2 = 30;
5. System.out.println("prmth2 = " + mth2);
6. }
7. public abstract void prmth3();
8. }
What is the result?

  1. Compilation fails because of an error on line 3

  2. Compilation fails because of an error on line 1

  3. Compilation succeeds

  4. Compilation fails because of an error on line 7      

446. Choose the item that is not part of Java:

  1. Garbage collection  c. True Pointers

  2. Interfaces d. Multi-threading   

447. java.lang.Object does not contain which method?

  1. toString() c. It contains none of these

  2. equals()    d. exit()   

448. Which of the following expressions are legal? (Choose one or more.)

  1. int x = 6; if (!(x > 3)) {} c. int x = 6; x = !x;

  2. int x = 6; x = ~x;

449. Assume class B extends class A. They are defined as follows:
class A {
int x = 10;
public addX(){
x = x +1;
}
} // end of class A
class B extends A{

public B(){


super.addX();
x = x*10;
super.addX();
}
}//end of class B

Assume bbb is a reference to a B object, that is, "B bbb = new B(); ". What is the value of x in bbb?



  1. x = 111 b. x = 10 c. x = 11 d. x = 110

450. What is the output of the following code (assume only 8 bits for sanity)?
   System.out.println (~7);

  1. none of the above b. 8 c. 3 d. -8 e. -24

451. Where can a protected variable be accessed?

  1. any class

  2. only from the code within any subclass of the class in which it is defined

  3. only from the code within the same class in which it is defined.

  4. both from the code within the same class in which it is defined, and from the code within any subclass of the class in which it is defined.

452. True or False: The File class contains a method that changes the current working directory.

  1. True b. False

454. What is the output of the following code?
   for (int j; ;++j) {
      if (j == 7) break;
      System.out.println (j);
   }

  1. numbers 0 to 7 c. numbers 1 to 6

  2. doesn't compile d. numbers 0 to 6 e. numbers 1 to 7

455. What is the range of values that can be assigned to a variable of type short?

  1. -2^15 through 2^15 – 1 b. 0 through 2^16 – 1 c. 0 through 2^32 – 1 d. It depends on the underlying hardware. e. -2^31 through 2^31 – 1

456. Which one of the following is true about final methods?

  1. Final methods must be overridden in any subclass

  2. Final methods cannot be overridden in any subclass

  3. Final methods can be overridden in any subclass

  4. Final methods must be defined in final classes

457. Variables in Java…

  1. Always represent objects. c. Need to be initialized before use.

  2. Never store a value . d. Store numerical values exclusively.

458. A class Animal has a subclass Mammal. Which of the following is true:


  1. Because of single inheritance, Mammal can have no siblings

  2. Because of single inheritance, Mammal can have no subclasses.

  3. Because of single inheritance, Mammal can have no other parent than Animal

  4. Because of single inheritance, Animal can have only one subclass.

459. Which of the following statements would fail to compile? (Select two)

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


    int j; for (int k=0, j=0; j+k!=10;j++,k++){
System.out.println("j is "+j+" k is "+k);
}
}

b. public static void main(String args[]) {
    int j, k; for (k = 0, j = 0; j+k!=10;j++,k++){
System.out.println("j is "+j+" k is "+k);
}
}

c. public static void main(String args[]) {
    for (int k=0, j=0; j+k!=10;j++,k++){
System.out.println("j is "+j+" k is "+k);
}
}

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


    int k; for (k=0, int j=0; j+k!=10;j++,k++){
System.out.println("j is "+j+" k is "+k);
}
}

460. Read this piece of code carefully


if("String".toString() == "String")
System.out.println("Equal");
else
System.out.println("Not Equal");

  1. the code will cause a compiler error

  2. the code will compile an print "Equal"

  3. the code will compile an print "Not Equal"

460. 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.setPreferredSize(100,100);

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

  3. f.setSize(100,100);

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

461. What is code reuse?

  1. To use previously written classes in a new program, rather than writing them from scratch

  2. To copy code word by word from other programs in a new program while writing from scratch

  3. To put all pieces of code in one class

  4. To put all pieces of code in one method

462. The following code will print:
1: Double a = new Double(Double.NaN);
2: Double b = new Double(Double.NaN);
3:
4: if( Double.NaN == Double.NaN )
5: System.out.println("True");

6: else
7: System.out.println("False");


8:
9: if( a.equals(b) )
10: System.out.println("True");
11: else
12: System.out.println("False");

  1. True b. False c. True d. False
    True True False False

463. Assume we have a listener class with a JLabel and a JTextField. Each time the user input a number into the textfield, the program should add 1 to the number then let the JLabel show the result. What should we fill in the ActionPerformed method part to finish this program? The listener class is defined as follows:

class TextListener implements ActionListener{


private JTextField theField;
private JLabel theLabel;

public TextListener(JTextField f, JLabel lbl) {


theField = f;
theLabel = lbl;
}//end of constructor

public void actionPerformed(ActionEvent event) {


// to be filled in
}
}

  1. String num = theField.getText();
    int x = Integer.parseInt(num);
    int y = x+1;
    theLabel.setText(y);

  2. String num = theField.getText();
    theLabel.setText(num+1);

  3. String num = theField.getText();
    double x = Double.parseDouble(num);
    double y= x+1;
    theLabel.setText(""+y);

  4. String num = theField.getText();
    theLabel.setText("num+1");

464. When you call a modifying method on a String, what happens to the original String?

  1. It remains, a new String is created and the reference is updated to point to that String.

  2. It is immediately destroyed and a new String is created and the reference is updated to point to the new String.

  3. It remains, a new StringBuffer object is created and returned.

  4. It is immediately destroyed, and a new StringBuffer object is created and returned.

465. What is wrong with the following pair of classes?
public class Vehicle
{
    private float weight;
}

public class Boat extends Vehicle


{
// -------- Constructor --------
public Vehicle()
{
    weight = 100;
   // Initialise boat weight.
}
}

  1. There is nothing wrong with the classes as given.

  2. The class Vehicle should have a constructor.

  3. weight should be initialised inside Vehicle.

  4. The Boat class does not know about the object variable weight.

466. How do you get the x and y coordinates of mouse clicks?

  1. public void mouseClicked (){
    int x = getX();
    int y = getY(); }

  2. public void draw (MouseEvent event){
    int x = event.getX();
    int y = event.getY(); }

  3. public void mouseClicked (MouseEvent event){
    int x = getX();
    int y = getY(); }

  4. public void mouseClicked (MouseEvent event){
    int x = event.getX();
    int y = event.getY(); }

467. Which of the following is not a control structure?

  1. for(...) b. then(...) c. while(...) d. if(...)

468. In question 5, assume the Circle class also has a private method called getDiameter. Will this method appear in the Web documentation generated by javadoc?

  1. Yes, as long as it uses java doc comments

  2. Yes, every method should appear in the Web documentation unconditionally

  3. Yes, because the class Circle is defined public

  4. No, because it can't be accessed from outside the class and hence is not part of the abstraction. It is part of the implementation instead.

469. How many components can be added to each region of the BorderLayout?

  1. 0 b. infinite c. 2 d. 1

470. Accessor methods are useful because...

  1. they allow encapsulated information to be passed between objects in a controlled way

  2. they make a class's variables private.

  3. they minimise the amount of information passed between classes.

  4. make a class's variables public.

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

  1. the current class c. the current meth d. a number

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

473. Is this statement legal in Java?
byte b =+6;

  1. No b. Yes



- -

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