31
Câu 1 Statement 1) The call to update( ) results in a call to the repaint( ). Statement 2) The paint( ) method clears the screen of any existing contents. Câu 1: kết quả vủa việc gọi update() là gọi repaint() Câu 2: phương thức paint() xóa tất cả nội dung trên màn hình [A]Statement 1) is TRUE and statement 2) is FALSE. [B]Statement 1) is FALSE and statement 2) is TRUE [C]Both the statements are TRUE. [D] Both the statements are FALSE. Câu 2 The call to _____ method causes the flicker as the screen is cleared between the frames. Gọi phương thức _____ là nguyên nhân màn hình được xóa giữa các frames public void update(Graphics g) [A] public void init() [B] public void start() [C] public void showStatus(String msg) [D] public void stop() [E] Which method causes the flicker is Depends on the particular implementation of the Java Virtual Machine [F] Câu 3 What is the default alignment for a FlowLayout? Vị trí sắp xếp mặc định của FlowLayout là gì? [A] FlowLayout.CENTER

De thi 72 cau

Embed Size (px)

Citation preview

Page 1: De thi 72 cau

Câu 1Statement 1) The call to update( ) results in a call to the

repaint( ). Statement 2) The paint( ) method clears the screen of any existing

contents. Câu 1: kết quả vủa việc gọi update() là gọi repaint()Câu 2: phương thức paint() xóa tất cả nội dung trên màn hình

[A]Statement 1) is TRUE and statement 2) is FALSE. [B]Statement 1) is FALSE and statement 2) is TRUE[C]Both the statements are TRUE. [D]Both the statements are FALSE.

Câu 2The call to _____ method causes the flicker as the screen is cleared between the frames. Gọi phương thức _____ là nguyên nhân màn hình được xóa giữa các framespublic void update(Graphics g) [A]public void init() [B]public void start() [C]public void showStatus(String msg) [D]public void stop() [E]Which method causes the flicker is Depends on the particular implementation of the Java Virtual Machine [F]

Câu 3What is the default alignment for a FlowLayout? Vị trí sắp xếp mặc định của FlowLayout là gì?[A]FlowLayout.CENTER [B]FlowLayout.LEFT [C]FlowLayout.RIGHT [D]Depends on the particular implementation of the Java Virtual Machine

Câu 4Which of the following loop constructs must execute their loop body at least once?.

Page 2: De thi 72 cau

Cấu trúc lặp nào sau đây phải thực hiện ít nhất 1 lần?[A] while (<boolean-expression>) <statements>...[B]do <statements>... while (<boolean-expression>);

[C]for (<init-stmts>...; <boolean-expression>; <exprs>...) <statements>... [D]Depends on the particular implementation of the Java Virtual Machine

Câu 5An overridden method can be in the same class. Một phương thức ghi đè có thể giống lớp?[A]True [B]False [C]Depends on the particular implementation of the Java Virtual Machine

Câu 6Which of the following datatypes the most bits to repconsumes resent its range of values? Loại dữ liệu nào sau đây với số bit nhiều nhất mà dùng hết phạm vi giá trị của nó?[A]boolean [B]float[C]long[D]char[E]Depends on the particular implementation of the Java Virtual Machine JAVA1 Duration: 60 mins - Total: 60 marks.Question PaperPage 1 of 12 00040380A3

Câu 7The following code will giveĐoạn code sau trả lại gì?

Page 3: De thi 72 cau

1: Byte b1 = new Byte("127"); 2: 3: if(b1.toString() = = b1.toString()) 4: System.out.println("True"); 5: else 6: System.out.println("False");

[A] Compilation error, toString() is not avialable for Byte.[B] Prints "True" [C]Prints "False". [D]Depends on the particular implementation of the Java Virtual Machine [E]Runtime error Lý do: cứ mỗi lần gọi b1.toString = việc có 1 biến String s mới lưu trữ >> có 2 biến s1, s2 với địa chỉ trên Heap khác nhauCâu 8The following code will printĐoạn code sau in ra gì?1: int i = 1; 2: i <<= 31; 3: i >>= 31; 4: i >>= 1; 5: 6: int j = 1; 7: j >>= 31; 8: j >>= 31; 9: 10: System.out.print("i = " +i ); 11: System.out.println("\tj = " +j);

[A]i = 1 j = 1 [B]i = 1 j = -1 [C]i = -1 j = 0 [D]compiler error [E]runtime error [F]Depends on the particular implementation of the Java Virtual Machine

Page 4: De thi 72 cau

Do biến kiểu int có 4 byte, nên lưu trữ đc 32 bit. Bít 31 lưu dấuKhi x<<=m, in ra x=2^m (m<31)

Câu 9Which of the following statements regarding the ‘final’ modifier are true? [A]A variable defined as ‘final’ is a constant [B]A class declared as being ‘final’ can be subclassed [C]A method declared ‘final’ cannot be overridden in the subclass [D]A class declared as being ‘final’ cannot be subclassed [E]A method declared ‘final’ can be overridden in the subclass

Câu 10You want the program to print 3 to the output. What of the following values for x will do this?

switch(x){ case(1): System.out.println(“1”); case(2): case(3): System.out.println(“3”); }

[A]1[B] 2[C] 3[D]4 [E]0Truyền x=1,2,3 >> đều in ra 3, nhưng truyền x=1 in ra 1 và 3 >> đáp án B,C

Câu 11The following lists the complete contents of the file named Derived.java: 1. public class Base extends Object 2. {3. String objType ;4. public Base()5. {

Page 5: De thi 72 cau

6. objType = "I am a Base type" ; 7. } 8. } 9. public class Derived extends Base 10. { 11. public Derived() 12. {13. objType = "I am a Derived type" ; 14. } 15. public static void main(String args[])16. { 17. Derived D = new Derived() ; 18. } 19. }

What will happen when this file is compiled?[A]Two class files, Base.class and Derived.class, will be created. [B]The compiler will object to line 1. [C]The compiler will object to line 7. Trong 1 file chỉ có 1 class public trùng tên với file đó

Câu 12You are writing a set of classes related to cooking and have created your own exception hierarchy derived from java.lang.Exception as follows:

Exception +-- BadTasteException

+-- BitterException +-- SourException

BadTasteException is defined as an abstract class.

You have a method eatMe that may throw a BitterException or a SourException. Which of the following method declarations will be acceptable to the compiler?

[A]public void eatMe( Ingredient[] list ) throws BadTasteException

Page 6: De thi 72 cau

[B]public void eatMe( Ingredient[] list ) throws BitterException, SourException [C]public void eatMe( Ingredient[] list ) may throw BadTasteException c[D]public void eatMe( Ingredient[] list ) Hị hị câu nì bó tay

Câu 13Which of the following statements about finalize methods are incorrect? - không chính xác[A]The purpose of a finalize method is to recover memory and other system resources. [B]The purpose of a finalize method is to recover system resources other than memory. [C]You should always write a finalize method for every class. [D]The order in which objects are created controls the order in which their finalize methods are called.

Câu 14

Which of the following statements about Java garbage collection are true? [A]The following code will start the garbage collection mechanism:

System.gc() ; Thread.yield() ;

[B]Calling Runtime.getRuntime().gc() will probably start the garbage collection mechanism, but there is no guarantee. [C]The garbage collection Thread has a low priority.[D]The method by which Java determines that a chunk of memory is garbage is up to the implementer of the JVM.

Thread.yield() ; >> đưa ra các luồng khác một khả năng thực thi. Giúp tất cả các luồng có quyền ưu tiên ngang nhau chia sẻ time thực thi CPU>> xem lại đáp án câu này

Page 7: De thi 72 cau

Câu 15Given the following method definition in a class that otherwise compiles correctly:

1. public boolean testAns(String ans,int n){2. boolean rslt ; 3. if( ans.equalsIgnoreCase("YES") && n > 5 ) rslt = true ; 4. return rslt ; 5. }

What will be the result of trying to compile the class and execute the testAns method with inputs of "no" and 5?

A runtime exception will be thrown in the testAns method. [A]A result of false will be returned. [B]A compiler error will prevent compilation. [C]A result of true will be returned. [D]Do dòng 2 chưa khởi tạo rslt

Câu 16Given that a class, Test, declares a member variable named "scores" as an array of int as follows:int scores[];

Which of the following code fragments would correctly initialize the member variable scores as an array of four ints with the value of zero if used in the Test constructor?

int scores[] = { 0,0,0,0} ; [A]scores = new int[4] ; [B]scores = new int[4] ; for( int i = 0 ; i < 4 ; i++ ){ scores[i] = 0 ; } [C]scores = { 0,0,0,0 } ; [D]Lý do: A: ko khai báo lại D: để khai báo trị chính xác giá trị của mảng ta phải khai báo theo cấu trúc

Kiểu dữ liệu[] tên_mảng={ds giá trị};

Page 8: De thi 72 cau

Câu 17What happens when you attempt to compile and run the following code?

1. public class Logic { 2. static long sixteen = 0x0010 ; //23. static public void main(String args[]){ 4. long N = sixteen >> 4 ; 5. System.out.println( "N = " + N ) ; 6. }7. }

The compiler will object to line 4, which combines a long with an int. [A]The program will compile and run, producing the output "N = 0". [B]The program will compile and run, producing the output "N = 1". [C]A runtime exception will be thrown. [D]

Câu 18In the following code fragment from an applet, we know that the getParameter call may return a null if there is no parameter named size:

1. int sz ; 2. public void init(){ 3. sz = 10 ; 4. String tmp = getParameter( "size" ) ; 5. if( tmp != null X tmp.equals( "BIG" )) sz = 20 ; 6. }

Which logical operator should replace X in line 5 to ensure that a NullPointerException is not generated if tmp is null?

Replace X with &. [A]Replace X with &&. [B]Replace X with |. [C]Replace X with ||. [D]

Page 9: De thi 72 cau

Câu 19Your programming problem is to create a list of unique values of part ID numbers in a large collection of data representing orders. Furthermore, it would be nice if the list was in sorted order.You have decided to use one of the collection classes in the java.util package to construct this list. Which of the following interfaces should the ideal class implement?

Map [A]SortedMap [B]List [C]Set [D]SortedSet [E]

Câu 20Given that you have a method scale defined as follows, where scalex and scaley are int constants:

public Point scale( int x, int y ){ return new Point(

( int )( x / scalex ), ( int )( y / scaley ) ) ;

}What will happen when you call this method with double primitives instead of int, as in the following fragment?

1. double px = 10.02 ; 2. double py = 20.34 ; 3. Point thePoint = scale( px, py ) ;

A compiler error occurs in line 3. [A]The program compiles but a runtime cast exception is thrown. [B]The program compiles and runs. [C]The compiler objects to line 1. [D]

Page 10: De thi 72 cau

Câu 21When creating your own class, and you want to make it directly support sorting, which interface must it implement?

Comparable [A]Comparator [B]Sortable [C]Sortator [D]Giao diện thường có đuôi “able” >> hoặc A hoặc C >> ko có C >> đáp án A

Câu 22Class A is a subclass of class B. What would happen if you try to sort an array of mixed elements of type A and B? They would sort based on the sorting method found in class A [A]They would sort based on the sorting method found in class B [B] Sorting would just leave the original array unsorted with no exceptions thrown [C]Sorting would yield a ClassCastException as the classes are incompatible [D]D >> xem xét lại

Câu 23When implementing the compareTo(Object first, Object second) method to support sorting, returning -1 means the first object comes sequentially before the second object. True [A]False [B]

int compareTo(String other)

returns a negative value if the string comes before other in dictionary order, a positive value if the string comes after other in dictionary order, or 0 if the strings are equal.

Câu 24If two equal objects are in an array and that array is sorted, the equal elements may change their order.

Page 11: De thi 72 cau

True [A]False [B]Equal so sánh chứ ko sắp xếp

Câu 25The rules for naming variables in Java are: (Choose all correct answers) The variable name must not begin with a numeric character [A]The variable name must be a maximum of 50 characters in length [B]The variable name must not be a keyword [C]The variable name can contain alphanumeric characters [D]Depends on the particular implementation of the Java Virtual Machine [E]alphanumeric characters – chữ cái hoặc số

Câu 26Which of the following statement related to java.awt package is true? The java.awt package contains classes that that form the base of the design of the programs [A]The java.awt package contains all classes used for Input and Output operations [B]The java.awt package contains classes used for creating graphical user interface applications [C]The java.awt package contains classes that that form the base of the analysis of the programs [D]Câu A sai do design of the programs >> sai

Câu 27A variable declared with the default modifier can be accessed by _____. (Choose all correct answers) different packages and different classes [A]same package different classes [B]same package sub classes [C]different packages and sub classes [D]all classes [E]the class containing that variable only [F]F sai do có only – chỉ lớp đó truy cập đc >> sai

Page 12: De thi 72 cau

Câu 28Which of the following statements regarding the ‘final’ modifier are true? (Choose all correct answers)

A variable defined as ‘final’ is a constant [A]A class declared as being ‘final’ can be subclassed [B]A method declared ‘final’ cannot be overridden in the subclass [C]A class declared as being ‘final’ cannot be subclassed [D]A method declared ‘final’ can be overridden in the subclass [E]

Câu 29Whenever an applet is created the _____ method is called.Khi 1 applet đc tạo >> phương thức nào đc gọi

public void init() [A]public void start() [B]public void initialize() [C]public void begin() [D]Which method is called is Depends on the particular implementation of the Java Virtual Machine [E]Kiểm tra trong corejava rồi

Câu 30Which of the following are true about a dead thread? The thread’s object is discarded [A] //discard: vứt bỏ, thải hồiThe thread must wait until all other threads execute before it is restarted [B]The thread cannot be restarted [C]The thread is synchronized [D]The thread can be restarted again [E]Thread ko thể restart và discarded >> loại A, B, ECâu D: mình có thể synchronized 1 thread, việc này ko tự động

Câu 31How do you change the current layout manager for a container? Use the setLayout(…) method [A]

Page 13: De thi 72 cau

Once created you cannot change the current layout manager of a component [B]Use the setLayoutManager(…) method [C]Use the updateLayout(…) method [D]Use the new Layout(…); statement [E]How to change the current layout manager for a container is Depends on the particular implementation of the Java Virtual Machine [F]Không có setLayoutManager(), updateLayout() >> loại C, DCó thể thay đổi Layout >> loại B, FE chưa kiểm tra nhưng search ebook ko thấy xài

Câu 32A container is an area where you can place your components True [A]False [B]

Câu 33The _____ is the standard error stream System.out class [A]System.err class [B]System.error class [C]System.bug class [D]System.defect class [E]Which stream is Depends on the particular implementation of the Java Virtual Machine [F]Không có system.bug và .defectIt is often handy to trap program errors in a file. However, errors are sent to System.err, not System.out. Therefore, you cannot simply trap them by running

Câu 34_____ allow you to organize your classes into smaller units and make it easy to locate and use the appropriate class file _____cho phép bạn tổ chức các lớp trong các thành phần nhỏ, giúp dễ dàng cho việc định vị và sử dụng lớp phù hợpClasspath [A]Package [B]Directory [C]

Page 14: De thi 72 cau

Folder [D]Depends on the particular implementation of the Java Virtual Machine [E]

Câu 35

The _____ event is handled when the mouse is out of the component mouseClicked [A]mouseEntered [B]mouseExited [C]mouseReleased [D]mouseOut [E]Depends on the particular implementation of the Java Virtual Machine [F]Không có mouseOut, mouseReleased: con chuột đc giải phóng

Câu 36Which method do you use to start a Thread? start() [A]init() [B]begin() [C]run() [D]departure() [E]Depends on the particular implementation of the Java Virtual Machine [F]

Câu 37Which of the following are legal identifiers. (Choose all correct answers)

2variable [A]variable2 [B]_whatavariable [C]_3_ [D]#myvar [E]

Page 15: De thi 72 cau

Câu 38What will be the output of the following code?

1. public class integerequals 2. {3. public static void main (String args[]) 4. { 5. Integer a= new Integer(0); 6. Integer b= new Integer(0); 7. System.out.println(a==b); 8. }9. }

The compiler will show an error at line 7 [A]The program compiles and prints true [B]The program compiles and prints false [C]The program compiles but causes a runtime exception at line 7 [D]

Câu 39The ActionListener interface has no corresponding Adapter class. // corresponding: tương thíchTrue [A]False [B]Depends on the particular implementation of the Java Virtual Machine [C]An interface such as ActionListener that has only a single method does not need an adapter class.

Câu 40All awt components can have a MouseListener. True [A]False [B]Depends on the particular implementation of the Java Virtual Machine [C]

Page 16: De thi 72 cau

Câu 41Which of the following illustrates the correct way to pass a parameter into an applet? <applet code=Test.class age=33 width=100 height=100> [A]<param name=age value=33> [B]<applet code=Test.class name=age value=33 width=100 height=100> [C]<applet code=Test.class param="name:age, value:33"> [D]Which way depends on the particular implementation of the Java Virtual Machine [E]Chỉ có cách truyền tham số với thẻ <param>

Câu 42You can declare native methods as Abstract.True [A]False [B]Depends on the particular implementation of the Java Virtual Machine [C]native methods bắt buộc phải có thân phương thứcví dụpublic native void aa(){} //sai

Câu 43A method called the Constructor is used to destroy an objectHàm khởi tạo để phá hủy 1 đối tượng True [A]False [B]There is no method called Constructor [C]

Câu 44The ability of an object to store data beyond the lifetime of the object is called encapsulation Khả năng 1 đối tượng lưu trữ 1 dữ liệu nào đó gọi là đóng góiTrue [A]False [B]Đ/N đóng gói: là tiến trình che dấu việc thực thi những chi tiết của một đối tượng đối với ng sử dụng đối tượng ấy

Page 17: De thi 72 cau

Câu 45The process of bringing an object into existence is called constructionQuá trình mang lại 1 đối tượng thực đc gọi là Khởi tạo True [A]False [B]

Câu 46The class that inherits from another class is called superclass True [A]False [B]

Câu 47An object is an instance of a classTrue [A]False [B]

Câu 48A class defines an entity, while an object is the actual entity 1 lớp đc định nghĩa là 1 thực thể, trong khi 1 đối tượng là 1 thực thể thậtTrue [A]False [B]

Câu 49

The _____ is a specification of how the requested operation is carried out Message [A]Operation [B]Method [C]Event [D]Attribute [E]

Câu 50_____ is the ability of an object to store data beyond the lifetime of the object

Page 18: De thi 72 cau

Khả năng 1 đối tượng lưu trữ dữ liệu trong vòng đời của đối tượng= khả năng 1 đối tượng của các lớp khác nhau có thể đáp ứng thực hiện các hành vi khác nhau của các lớp khác nhau.Persistence [A]Destruction [B]Construction [C]Encapsulation [D]Polymorphism [E]Inheritance [F]Person p1=new Person();Person p2=new Employee();Person p3=new Manager();//gọi cùng getDetail >> khác nhaup1.getDetail();p2.getDetail();p3.getDetail();

Câu 51_____ allows an operation to have different behaviour on different objects _____ cho phép 1 đối tượng có nhiều hành vi khác nhau trên đối tượng khác nhauPolymorphism [A]Encapsulation [B]Inheritance [C]Persistence [D] //bền vữngDestruction [E]Construction [F]Tính bền vững: khả năng lưu trữ dữ liệu của một đối tượng ngay cả khi đối tượng ấy không còn tồn tại

Câu 52In _____ inheritance a subclass inherits from two or more classes Single [A]Double [B]Multiple [C]Share [D]

Page 19: De thi 72 cau

Distributed [E]

Câu 53An object is.what classes are instantiated from [A]an instance of a class [B]a reference to an attribute [C]a variable [D]a concept of Object Oriented Programming [E]

Câu 54The _____ keyword allows the main() method to be called without needing to create an instance of the class.public [A]static [B]void [C]final [D]throws [E]

Câu 55The _____ keyword tells the compiler that the method does not return any value when executed public [A]void [B]static [C]break [D]continue [E]

Câu 56The _____ datatype is used to store a true or false value boolean [A]byte [B]char [C]array [D]Which datatype depends on the particular implementation of the Java Virtual Machine [E]

Page 20: De thi 72 cau

Câu 57Which of the following are decision making statements? (Choose all correct answers) if-else [A]switch-case [B]continue [C]break [D]return [E]

Câu 58The _____ datatype is used to store a true or false value 0.5 boolean [A]booleans [B]boors [C]bool [D]bools [E]boor [F]

Câu 59Which of the following are looping statements? (Choose all correct answers) while [A]do-while [B]for [C]if-else [D]loop [E]circle [F]

Câu 60_____ methods are rewritten in the subclass Overloaded [A]Overridden [B]private [C]static [D]public [E]protected [F]

Page 21: De thi 72 cau

Câu 61A method having _____ access specification can be viewed from any package or any class private [A]protected [B]public [C]default [D]package [E]

Câu 62Which of these classes can be added to any Container class, using the add method defined in Container class? (Choose all correct answers) Button [A]Label [B]List [C]TextArea [D]

---------------------------------đến đây toàn là giao diện thoai :D ko làmCâu 63In Java, which of these classes implement the LayoutManager interface? (Choose all correct answers) RowLayout [A]ColumnLayout [B]GridBagLayout [C]FlowLayout [D]BorderLayout [E]

Câu 64Which of the following layout manager is the default Layout Manager for the Applet class in Java? FlowLayout [A]BorderLayout [B]GridLayout [C]CardLayout [D]GridBagLayout [E]Which layout manager depends on the particular implementation of the Java Virtual Machine [F]

Page 22: De thi 72 cau

Câu 65The default alignment of buttons in Flow Layout is ...LEFT [A]CENTER [B]RIGHT [C]The alignment must be defined when using the FlowLayout Manager. [D]Depends on the particular implementation of the Java Virtual Machine [E]

Câu 66Which GridBagLayout variable defines the external padding (border) around the component in its display area? gridwidth, gridheight [A]gridx, gridy [B]fill [C]ipadx, ipady [D]insets [E]Depends on the particular implementation of the Java Virtual Machine [F]

Câu 67Which GridBagLayout variable specifies where (in which direction) a component should be placed in its display area?gridwidth, gridheight [A]gridx, gridy [B]anchor [C]fill [D]ipadx, ipady [E]Depends on the particular implementation of the Java Virtual Machine [F]

Câu 68To have a TextArea display scrollbars, you need to place it within a ScrollPane. True [A]

Page 23: De thi 72 cau

False [B]Depends on the particular implementation of the Java Virtual Machine [C]

Câu 69The CheckboxGroup is a subclass of Component. True [A]False [B]Depends on the particular implementation of the Java Virtual Machine [C]

Câu 70Using new TextField(10) will create a TextField that only accepts 10 characters of input. True [A]False [B]Depends on the particular implementation of the Java Virtual Machine [C]

Câu 71Can a container have multiple layout managers? Yes [A]No [B]Depends on the particular implementation of the Java Virtual Machine [C]

Câu 72Using only AWT classes, what is the simplest way to reserve space for a border around a component?Set the Insets of the component [A]Add the component to a container and set the Insets of the container [B]Set the Border of the component [C]Add the component to a container and set the Border of the container [D]