CoreJava_1

¡Supera tus tareas y exámenes ahora con Quizwiz!

Given the following code. Which of the following statemens can be legally inserted in place of the comment//Here? (Select two) class Base{} public class MyCast extends Base{ static boolean b1=false; static int i =-1; static double d = 10.1; public static void main(String argv[]){ MyCast m = new MyCast(); Base b = new Base(); //Here } } A. d=i; B. b=m; C. b1=i; D. m=b;

B

Select correct statement. (1) The Swing's list component (JList) can display text only. (2) The Swing's button (JButton) can not contain an image. (3) The Swing's lable (JLabel) can present an image. A. 1 B. 1,3 C. 3 D 2,3

B

What happens when you try to compile and run the following application? import java.io.*; class A{ String name; int age; A(String na, int ag){name = na; age = age;} } public clas Main{ public static void main(String argv[]){ try{ File f = new File("xxx.ser"); FileOutputSteam fos = new ObjectOutputSteam(f); ObjectOutputSteam oos = new ObjectOutputSteam(fos); oos.writeObject(new A("Hoa",22));//(1) oos.close();//(2) fos.close(); } catch(Exception x){} } }

B

What is the output when you try to compile and run the following program? public class Main{ public static void main(String[]args) { String s ="Hi there"; int pos = s.indexOf(" "); String s2 = new String(new char[] {'H', 'i'}); if(r.equals(s2)) System.out.println("EQUAL"); else System.out.println("NOT EQUAL"); System.out.println(); } A. There is a compile error in the program. B. EQUAL C. NOT EQUAL D. EQUAL NOT EQUAL

B

Which is the four steps are used in working with JDBC A. 1)Create a statement and execute the query 2)Create the connection 3)Look at the result set 4)Close connection B. 1)Connect to the database 2)Create a statement and excute the query 3)Look at the result set 4)Close connection C. 1)Load driver 2)Create astatement and excute the query 3)Look at the result set 4)Close connection D. 1)Create a statement and excute the query 2)Load driver 3)Look at the result set 4)Close connection

B

Which line contains only legal statements? A. String x = "Hello", int y =9; if(x==y){} B. String x = "Hello", int y=9; x=x+y; C. String x = "Hello", int y=9; y=y+x; D. String x = "Hello", int y=9; y+=x;

B

Which of the following is true? A. An enum definition may contain the main() method of an application. B. You cannot call an enum's toString() method. C. you cannot call an enum's wait() method. D. You cannot call an enum's notify() method.

B

Which of the following statements is INCORRECT? A. All of the methods in an interface are implicitly abstract B. A method in an interface can access class level variables C. All of the variables in an interface are implicitly final D. All of the variables in an interface are implicitly static

B

Consider the following code developed in NetBeans. What does the thread t do? (cái này có hình) A. It will show nothing B. It will show a clock in the JLabel1 C. The program cause errors when it is compiled. D. It will show a full-formatted current date in the JLabel1

C

Select the correct statement which set the layout manager of a given frame to FlowLayout Manager. A. setFlowLayout(); B. setLayoutManager(new FlowLayout()); C. setLayout(new FlowLayout()); D. addLayout(new FlowLayout());

C

Suppose class X contains the following method: void doSomething(int a, float b) {...} Which of the following methods may appear in class Y, which extends X? A. public void doSomething(int a, float b) throws java.io.IOException {...} B. private void doSomething(int a float b) {...} C. public void doSomething(int a, float b) {...} D. private void doSomething(int a, float b) throws java.io.IOException {...}

C

What is 7 % -4? A. -4 B. -3 C. 3 D. 4

C

What will happen when you attempt to compile and run this code? class Base{ abstract public void my function(); public void another(){ System.out.println("Another method"); } } public class Abs extends Base{ public static void main(String argv[]){ Abs a = new Abs(); a.amethod(); } public void myfunc(){ System.out.println("My func"); } public void amethod(){ myfunc(); } } A. The code will compile and run, printing out the words "My Func" B. The code will compile but complain at runtime that the Base class has non abstract methods. C. The compiler will complain that the Base class is not declare as abstract. D. The compiler will compalin that the method myfunc in the base class has no body.

C

Which of the following is a valid argument to the DataInputSteam constructor? A. File Reader B. File C. FileInputSteam D. RandomAccessFile

C

Which of the following statement is true? A. FlowLayout is the default layout manager every JFrame. B. BorderLayout is the default layout manager for every JPanel. C. BorderLayout is the default layout manager for every JFrame. D. FirdLayout is the default layout manager for every JPanel.

C

Which of the following statements is true about two base protocols used for networking: TCP(Transmission Control Protocol) and UDP (User Database Protocol)? A. TCP is not a connection-based protocol and UDP is connection-based protocol. B. TCP and UDP are connection-based protocols. C. TCP is a connection-based protocol and UDP is not connection-based protocol. D. TCP and UDP are not connection-based protocols.

C

Given the following code, what test would you need to put in place of the comment line? // place test here to result in an output of the string Equal public EqTest{ public static void main(String argv[]){ Eq Test e= new EqTest(); } EqTest(){ String s ="Java"; String s2="java"; //place test here{ System.out.println("Equal"); } else { System.out.println("Not Equal"); } } } A. it(s.noCaseMatch(s2)) B. if(s.equal(s2)) C. if(s==s2) D. if(s.equaIsIgnoreCase(s2))

D

Given: 10. class Line{ 11. public static class Point{} 12.} 13. 14. class Triangle{ 15. //insert code here 16. } Which code, inserted at line 15, creates an istance of the Point class defined in Line? A. Line Point p = new Line.Point(); B. Point p = new Point(); C. the Point class cannot be instatiated at line 15. D. Line l = new Line(); Point p = new l.Point();

D

How can you force garbage collection of an object? A. call System.gc(). B. Set all reference to the object to new values(null, for example). C. Call System.gc(). passing in a reference to the object to be garbage-collected. D. Garbage collection cannot be forced. E. Call Runtime.gc().

D

How do you prevent shared data from being corrupted in a multithreaded environment? A. Use only static variables. B. Mark all vatiables as volatile. C. Mark all variables as synchronized. D. Access the variables only via synchronized methods.

D

Select the most correct statement A. A protected method may only be accessed by the class in which it is declared or by the subclasses of that class. B. A protected method may only be accessed by classes or interfaces of the same package. C. A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared. D. A protected method may only be accessed by classes of the same package or by subclasses of the class in which it is declared.

D

What will be output when the following code is run? class Test {public int fun(int x) {int count=1; try { count +=x; foo(count); } catch(Exception e) {count -=x;} return(count); } public int foo(int k){ if(true) throw new ArithmeticException(); return(k); } class Main { public static void main(String[] args) { Test t = new Test(); System.out.println(t.fun(2)); } } A. 2 B .3 C. 4 D.1 E.5

D

What will happen if you try to compile and run the following code? public class Q { public static void main(String argv[]){ int anar[]=new int[]{1,2,3}; System.out.println(anar[1]); } } A. Error: size of array must be defined B. 1 C. Error anar is referenced bedore it is initialized D. 2

D

What will happen when you attempt to compile and run the following code? public class Main{ public static void main(String argv[]){ A t = new A("One"); t.run(); A h = new A("Two"); h.run(); } class A extends Thread{ for(int i=0; i<2;i++){ try{ sleep(1000); }catch(InterruptedException e){} yield(); System.out.print(sTname+" "); } } } A. Compile time error, class Rpcraven does not import java.lang.Thread B. Compilation but no output at runtime C. Output of One Two One Two D. Output of One One Two Two

D

Whenever a method does not want to handle exceptions using the try block, the ______ is used. A. throwable B. nothrows C. throw D. throws

D

Which of the following is INCORRECT? A. String x="ABC"+2 B. char c = 0x1234; C. char c = '\u1234'; D char c = \u1234;

D

Which of the following is legal? A. double d = 1.2h; B. double d = 1.2D5; C. double d = 1.2d5; D double d = 1.2d;

D

Which of the following methods of the Collections class can be used to find the largest value in a Vector? A. Collections.max() B. Collections.maxElement() C. Collections.maxValue() D. We don't need any method because elements in Vector are automatically sorted. Therefore, the first element contains the maximum value.

D

Which of the following operations might throw an ArithmeticException? A. + B. - C. * D. %

D

Which of the following statements is INCORRECT about a non-static synchronized method? A. It can call to the same method of the current object. B. It can call to the same method of a differenct instance of the current class. C. It can call to a differenct synchronized method of the current object. D. It cannot call to a static synchronized method of the current class.

D

Which the statements blow are true? A. To change the currect working directory, call the setWorkingDirectory() method of the File class. B. To change the currect working directory, call the cd() method of the File class. C. To change the currect working directory, call the changeWorkingDirectory() method of the File class. D. To check whether the file denoted by the abstract pathname is a directory or not, call the isDirectory() method of the File class.

D

The default type of the ResultSet object is.... A. TYPE_NORMAL B. TYPE_SCROLL_INSENSITIVE C. TYPE_SCROLL_SENSITIVE D. Non of the others E. TYPE_FORWARD_ONLY

E

Given a string constructed by calling s = new String("xyzzy"). which of the calls modifies the string? A. s.apped("aaa"); B. s.strim(); C s.substring(3); D. s.replace('z','a'); E. s.concast(s); F. Non of the others

F

What will happen when you attempt to compile and run the following code? public class Tux extends Thread{ static String sName="ABC"; public static void main(String argv[]){ Tyx t = new Tux(); t.piggy(sName); System.out.println(sName); } public void piggy(String sName){ sName=sName+ "DE"; start(); } public void run(){ for(int i=0;i < 4;i++){ sName = sName + "" +i; } } } A.Compilation and output of either "ABC", "ABC 0", "ABC 0 1" "ABC 0 1 2" or "ABC 0 1 2 3" B. Compilation and output of "ABC DE 0 1 2 3" C. Compilation and output of "ABC DE" D. Compile time error

no solution ..........wait

Select the most correct statement. A. A(non-local) inner class maybe declared as public, static, final, or abstract. B. A(non-local) inner class maybe declared as public, protected, static or final. C. A(non-local) inner class maybe declared as public, protected, private, static, final, or abstract. D. A(non-local) inner class maybe declared as protected, static, final, or abstract.

no solution.....wait

A signed data type has an equal number of non-zero positive and negative values available. A. False B. True

A

In RMI implementations, all methods, declated in the remote interface, must throw the ... exception. A. java.rmi.RemoteException B. java.rmi.NetworkException C. java.rmi.RmiException D. java.lang.Exception E. Non of the others

A

Suppose aslaries is an array containing floats. Which of the following are valid loop control statements for processing each element of salaries? A. for(float f:salaries) B. for(int i;;salaries) C. for(int i:salaries) D. for(float f::salaries)

A

Suppose the declared type of x is a class, and the declared type of y is an interface. When is the assignment x = y; legal? A. When the type of x is Object B. When the type of x is an array C. Never D. Always

A

The _____ class is the primary class that has the driver information. A. DriverManager B. Driver C. ODBCDriver D. Non of the others

A

What method of the java.io.File class can create a file on the hard drive? A. createNewFile() B. createFile() C. newFile() D. makeFile(0 E. makeNewFile()

A

What will happen if you attempt to compile and run the following code? class Base{} class Sub extends Base{} class Sub2 extends Base{} public static void main(String []args) { Base b= new Base(); Sub s=(Sub) b; } } A. Runtime Exception B. Compile and run without error C. Compile time Exception

A

What will happen when you attempt to compile and run the following code? public class Bground extends Thread{ Brground b = new Bground(); b.run(); } public void start(){ for(int i =0; i<10;i++) { System.out.println("Value of i=" +i); } } } A. A run time error indicating taht no run method is defined for the Thread class B. A compile time error indicating that no run method is defined for the Thread class C. Clean compile but no output at runtime D. Clean compile and at run time the values 0 to 9 are printed out

A

Which of the following methods of the java.io.File can be used to create a newfile? A. createNewFile() B. newFile() C. There is no such method. Just do File f=new File("filename.txt") then the new file, named filename.txt will be created. D. makeNewFile()

A

Which of the following statements is correct? A. Both primitives and object references can be both coverted and cast. B. Only object references are converted automatically: to change the type of a primitive. you have to do a cast. C. Only primitives are converted automatically: to change the type of an object reference. you have to do a cast. D. Arithmetic promotion of object references requires explicit casting.

A

Which of the following statements is incorrect? A. Vector does not allow duplicate elements. B. TreeSet does not allow duplicate elements. C. Values stored in TreeSet are automatically sorted. D. ArrayList can duplicate elements.

A

Which of the following statements are true? (Select two) A. Inder no circumstances can a class be defined with the private modifier B. Adding more classes via import statements will cause a performance overhead, only import classes you actyally use. C. An interface cannot be instantiated D. A inner class may under some circumstances be difined with the protected modifier

A B

Consider the following class definition: 1. public class Test extends Base{ 2. public Test(int j){ 3. } 4. public Test(int j, int k) { 5. super(j,k); 6. } 7. } Which of the following forms of constructor must exist explicitly in the definition of the Base class? Assume Test and Base are in the asme package. (Select two) A. Base(){} B. Base(int j){} C. Base(int j, int k){} D Base(int j, int k){}

A D


Conjuntos de estudio relacionados

Repetition(Anaphora, Anadiplosis, Epistrophe, Epizeuxis, Epanalepsis, and Polyptoton)

View Set

1533 Exam 2 Comfort, Metabolism, Acid/Base, Nutrition

View Set

Illustrator GMetrix Exam Study Guide Lesson 2-2 (Non-Printing Tools and Import Assets)

View Set