key java

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

b. Test t = new Test(1); c. Test t = new Test(1, 2);

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 are legitimate calls to construct instances of the Test class? (Select two) a. Test t = new Test(); b. Test t = new Test(1); c. Test t = new Test(1, 2); d. Test t = new Test(1, 2, 3); e. Test t = (new Base()).new Test(1);

b. Test t = new Test(1);

Consider the following class definition: 1. public class Test extends Base { 2. public Test(int j) { 3. } 4. } Which of the following is legitimate call to construct instances of the Test class? a. Test t = new Test(); b. Test t = new Test(1); c. Test t = new Test(1, 2); d. Test t = new Test(1, 2, 3);

c. Base(int j, int k) { }

Consider the following class definition: 1. public class Test extends Base { 2. public Test(int j, int k) { 3. super(j, k); 4. } 5. } Which of the following form of constructor must exist explicitly in the definition of the Base class? Assume Test and Base are in the same package. a. Base() { } b. Base(int j) { } c. Base(int j, int k) { } d. Base(int j, int k, int l) { }

a. It will show a clock in the jLabel1

Consider the following code developed in NetBeans. What does the thread t do? [file:7891.jpg] a. It will show a clock in the jLabel1 b. The program cause errors when it is compiled. c. It will show a full-formatted current date in the jLabel1 d. It will show nothing

a. a, b, d, e

Consider the following definition: 1. public class Outer { 2. public int a = 1; 3. private int b = 2; 4. public void oMethod() { 5. int c = 3; final int d = 4; 6. class Inner { 7. private void iMethod(int e) { 8. 9. } 10. } 11. } 12. } Which line contain only variables, which can be referenced at line 8? a. a, b, d, e b. a, b, c, e c. a, b, e d. a, c, d, e

b. public int aMethod(int a, int b) throws Exception {...} d. public float aMethod(float p, float q) {...}

Consider these classes, defined in separate source files: 1. public class Test1 { 2. public float aMethod(float a, float b) throws IOException {.. } 3. } 1. public class Test2 extends Test1 { 2. 3.} Which of the following methods would be legal (individually) at line 2 in class Test2? (Choose two) a. float aMethod(float a, float b) {...} b. public int aMethod(int a, int b) throws Exception {...} c. public float aMethod(float a, float b) throws Exception {...} d. public float aMethod(float p, float q) {...}

a. public int amethod(int z){}

Given the following class definition public class Upton{ public static void main(String argv[]){ } public void amethod(int i){} //Here } Which of the following would be illegal to place after the comment //Here ? a. public int amethod(int z){} b. public int amethod(int i,int j){return 99;} c. protected void amethod(long l){ } d. private void anothermethod(){}

f. Compilation fails because of an error in line 19.

Given: 10. class Main { 11. static class A { 12. void process() throws Exception { throw new Exception(); } 13. } 14. static class B extends A { 15. void process() { System.out.println("B "); } 16. } 17. public static void main(String[] args) { 18. A a=new B(); 19. a.process(); 20. } 21. } What is the result when the above code is run? a. B b. The code runs with no output. c. An exception is thrown at runtime. d. Compilation fails because of an error in line 15. e. Compilation fails because of an error in line 18. f. Compilation fails because of an error in line 19.

a. Comparable interface and its compareTo method.

In order for objects in a List to be sorted, those objects must implement which interface and method? a. Comparable interface and its compareTo method. b. Comparable interface and its compare method c. Compare interface and its compareTo method d. Comparable interface and its equals method

e. int, long, float, double

In the following code, what are the possible types for variable result? (Select the most correct answer) 1. byte b = 11; 2. short s = 13; 3. result = b * ++s; a. byte, short, int, long, float, double b. boolean, byte, short, char, int, long, float, double c. byte, short, char, int, long, float, double d. byte, short, char e. int, long, float, double

b. No

Is the following code valid? 1. public abstract class Test1 { 2. abstract void aMethod(); 3. } 4. public class Test2 extends Test1 { 5. 6.} a. Yes b. No

b. No

Is the following code valid? 1. public class Test1 { 2. final void aMethod() {.. } 3. } 4. public class Test2 extends Test1 { 5. void aMethod() {.. } 6.} a. Yes b. No

b. No

Is the following code valid? public class Test1 { public static void main(String[] args) { final int a = 5; a = 10; } } a. Yes b. No

a. True

One way to approach the daunting number of Swing components is to divide them into three categories: Container components Ordinary components Menu components a. True b. False

d. WHERE

SQL keyword ___ is followed by the selection criteria that specify the rows to select in a query a. FROM b. ORDER BY c. HAVING d. WHERE

a. GridBagLayout

See picture: [file:7904.jpg] a. GridBagLayout b. BorderLayout c. GridLayout d. FlowLayout e. CardLayout

c. To make the new object available for client connections, call its accept() method, which returns an instance of ServerSocket

Select INCORRECT statement about ServerSocket class. a. The most useful form of the ServerSocket constructor is public ServerSocket(int portNumber) b. A server socket, on the other hand, makes itself available and then waits for clients to initiate connections. c. To make the new object available for client connections, call its accept() method, which returns an instance of ServerSocket d. There is no way to know how long the accept() call will take.

a. 1,2

Select correct statement(s). (Select one option) (1) Swing is part of the Java Foundation Classes and provides a rich set of GUI components. (2) Before you think about what your GUI will look like, it's important to think about what it will. a. 1,2 b. 1 c. 2 d. None of the others.

a. If a checked exception may be thrown within the body of a method, the method must either catch the exception or declare it in its throws clause.

Select the most correct statement: a. If a checked exception may be thrown within the body of a method, the method must either catch the exception or declare it in its throws clause. b. If a checked exception may be thrown within the body of a method, the method must catch the exception. c. If a checked exception may be thrown within the body of a method, the method must declare it in its throws clause. d. If a checked exception may be thrown within the body of a method, the method must catch the exception and declare it in its throws clause.

c. Both 1 and 2 are true

Study the statements: 1)When a JDBC connection is created, it is in auto-commit mode 2)Once auto-commit mode is disabled, no SQL statements will be committed until you call the method commit explicitly a. Only statement 1 is true b. Only statement 2 is true c. Both 1 and 2 are true d. Both 1 and 2 are not true

b. Compilation takes slightly more time.

Suppose a source file contains a large number of import statements. How do the imports affect the time required to compile the source file? a. Compilation takes no additional time. b. Compilation takes slightly more time. c. Compilation takes significantly more time. d. Compilation takes slightly less time.

a. for (float f:salaries)

Suppose salaries 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 (float f::salaries) d. for (int i::salaries)

a. True

We can access a static variable through the class name? a. True b. False

a. The program will print out: 18

What happens when you try to compile and run the following program? import java.util.*; public class Main{ public static void main(String argv[]){ TreeSet<Integer> t = new TreeSet<Integer>(); t.add(12); t.add(2); t.add(4); t.add(2); Iterator<Integer> i = t.iterator(); int sum=0; while(i.hasNext()) sum += i.next(); System.out.println(sum); } } a. The program will print out: 18 b. The program will print out: 20 c. The program will print out: 16 d. The program has a compile error.

b. Compilation fails due to an error in line 29.

What happens when you try to compile and run this application? 23. Object [] myObjects = { 24. new Integer(12), 25. new String("foo"), 26. new Integer(5), 27. new Boolean(true) 28. }; 29. java.util.Array.sort(myObjects); 30. for( int i=0; i<myObjects.length; i++) { 31. System.out.print(myObjects[i].toString()); 32. System.out.print(" "); 33. } a. Compilation fails due to an error in line 23. b. Compilation fails due to an error in line 29. c. The value of all four objects prints in natural order. d. A ClassCastException occurs in line 31.

a. When a task invokes its yield() method, it returns to the ready state. When a task invokes its sleep() method, it returns to the waiting state.

What is the difference between yielding and sleeping? a. When a task invokes its yield() method, it returns to the ready state. When a task invokes its sleep() method, it returns to the waiting state. b. When a task invokes its yield() method, it returns to the waiting state. When a task invokes its sleep() method, it returns to the ready state. c. There is no difference between yielding and sleeping

d. 99 100 102

What is the output when the following program is run? class A {public int x;} public class Main {static void fun(A t) {t.x += 2;} public static void main(String args[]) {A t = new A(); t.x = 99; System.out.print(t.x + " "); t.x++; System.out.print(t.x + " "); fun(t); System.out.println(t.x); } } a. 99 99 101 b. 99 100 101 c. 98 99 101 d. 99 100 102 e. 99 100 100

d. An boolean

What is the return type of the instanceof operator? a. A reference b. A class c. An int d. An boolean

b. The output: b contains 5

What results from running the following code? 1. public class Xor { 2. public static void main(String args[]) { 3. byte b = 10; // 00001010 binary 4. byte c = 15; // 00001111 binary 5. b = (byte)(b ^ c); 6. System.out.println("b contains " + b); 7. } 8. } a. The output: b contains 10 b. The output: b contains 5 c. The output: b contains 250 d. The output: b contains 245

d. 4

What will be output when the following code is run without throwing Exception? class Test {public int foo(int x) {int count=1; try { count += x; fun(count); count++; } catch(Exception e) { count -= x; } return(count); } public void fun(int k) {k++; } } class Main {public static void main(String [] args) {Test t = new Test(); System.out.println(t.foo(2)); } } a. 1 b. 2 c. 3 d. 4 e. 5

d. Exception raised: "java.lang.ArrayIndexOutOfBoundsException: 2"

What will be printed out if this code is run with the following command line? java myprog good morning public class myprog{ public static void main(String argv[]) { System.out.println(argv[2]); } } a. myprog b. good c. morning d. Exception raised: "java.lang.ArrayIndexOutOfBoundsException: 2"

c. 0

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[5]; System.out.println(anar[0]); } } a. Error: anar is referenced before it is initialized b. null c. 0 d. 5

d. Compilation and output of either "ABC", "ABC 0", "ABC 0 1" "ABC 0 1 2" or "ABC 0 1 2 3"

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[]){ Tux 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. Compile time error b. Compilation and output of "ABC DE" c. Compilation and output of "ABC DE 0 1 2 3" d. Compilation and output of either "ABC", "ABC 0", "ABC 0 1" "ABC 0 1 2" or "ABC 0 1 2 3"

c. float

When a short is added to a float, what is the type of the result? a. short b. int c. float d. double

b. False

When you call start() method of a thread, the code inside method run() will run immediately a. True b. False

d. Choose layout managers.

Which is the last step of four-step approach to help you organize your GUI thinking? a. Identify needed components. b. Isolate regions of behavior. c. Sketch the GUI. d. Choose layout managers.

a. java.util.ArrayList

Which of the following class implement java.util.List? a. java.util.ArrayList b. java.util.HashMap c. java.util.TreeMap d. java.util.StackList

d. int i = 7; byte b = i;

Which of the following code snippets does not compile? a. Integer i = 7; b. Integer i = new Integer(5); int j = i; c. byte b = 7; d. int i = 7; byte b = i;

c. JText

Which of the following is NOT a swing component? a. JButton b. JOptionPane c. JText d. JTextArea

b. Vector <String> theVec = new Vector<String>();

Which of the following is VALID? a. List<String> theList = new Vector<String>; b. Vector <String> theVec = new Vector<String>(); c. Vector <String> theVec = new Vector<String>; d. Vector <String> theVec = new List<String>();

c. a==b

Which of the following is an example of a bool-expression? a. x = 6 b. m1.setText("Hello.") c. a==b d. 70

c. cause == bYes

Which of the following is an example of a bool-expression? a. x = 6 b. m1.setText("Hello.") c. cause == bYes d. 70

c. float f=1.01;

Which of the following is illegal statement? a. float f=1/3; b. int i=1/3; c. float f=1.01; d. double d=999d;

a. java.lang.int

Which of the following is invalid wrapper class a. java.lang.int b. java.lang.Float c. java.lang.Double d. java.lang.Boolean

b. import java.util.Vector.*.*;

Which of the following is legal import statement? a. import java.util.Vector; b. import java.util.Vector.*.*; c. import java.util.. d. import java.util.Vector

a. An enum definition may contain the main() method of an application.

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.

d. Classes

Which of the following may not be synchronized? a. Blocks within methods b. Static methods c. Blocks within static methods d. Classes

b. public void xyz(float f)

Which of the following may override a method whose signature is void xyz(float f)? a. private int xyz(float f) b. public void xyz(float f) c. private void xyz(float f) d. public int xyz(float f)

a. public void xyz(float f)

Which of the following may override a method whose signature is void xyz(float f)? a. public void xyz(float f) b. private void xyz(float f) c. public int xyz(float f) d. private int xyz(float f)

a. createNewFile()

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

a. public static void main(String arg[])

Which of the following signatures is valid for the main() method entry point of an application? a. public static void main(String arg[]) b. public static void main() c. public void main(String [] arg) d. public static int main(String [] arg)

a. An anonymous inner class may implement at most one interface.

Which of the following statement about inner class is true? a. An anonymous inner class may implement at most one interface. b. An anonymous inner class may implement arbitrarily many interfaces. c. An anonymous inner class that implements one interface may extend a parent class other than Object.

a. TCP provides a point-to-point channel for applications that require reliable connections. b. UDP is a protocol that sends independent packets of data, called datagrams, from one computer to another with no guarantee about arrival.

Which of the following statements are true? (Select two) a. TCP provides a point-to-point channel for applications that require reliable connections. b. UDP is a protocol that sends independent packets of data, called datagrams, from one computer to another with no guarantee about arrival. c. UDP is a protocol that sends independent packets of data, called datagrams, from one computer to another with guarantee about arrival.

a. An inner class may be defined as static d. An inner class may extend another class

Which of the following statements are true? (select two) a. An inner class may be defined as static b. There are NO circumstances where an inner class may be defined as private c. A programmer may only provide one constructor for an anonymous class d. An inner class may extend another class

b. All methods in an abstract class must be declared as abstract

Which of the following statements is INCORRECT? a. If a class has any abstract methods it must be declared abstract itself. b. All methods in an abstract class must be declared as abstract c. When applied to a class, the final modifier means it cannot be sub-classed d. transient and volatile are Java modifiers

c. An abstract class may be inherited.

Which of the following statements is true? a. An abstract class may be instantiated. b. An abstract class must contain at least one abstract method. c. An abstract class may be inherited.

b. A class that has one abstract method must be abstract class

Which of the following statements is true? a. An abstract class must have at least one abstract method b. A class that has one abstract method must be abstract class

d. Object references can be converted in both method calls and assignments, and the rules governing these conversions are identical.

Which of the following statements is true? a. Object references can be converted in assignments but not in method calls. b. Object references can be converted in method calls but not in assignments. c. Object references can be converted in both method calls and assignments, but the rules governing these conversions are very different. d. Object references can be converted in both method calls and assignments, and the rules governing these conversions are identical. e. Object references can never be converted.

b. package MyPackage; import java.awt.; class MyClass{}

Which of the following will compile without error a. import java.awt.; package Mypackage; class Myclass {} b. package MyPackage; import java.awt.; class MyClass{} c. This is a comment package MyPackage; import java.awt.; class MyClass{} d. package MyPackage; class MyClass{} import java.awt.;

b. package MyPackage; import java.awt.*; class MyClass{} c. /*This is a comment */ package MyPackage; import java.awt.*; class MyClass{}

Which of the following will compile without error (select two) a. import java.awt.*; package Mypackage; class Myclass {} b. package MyPackage; import java.awt.*; class MyClass{} c. /*This is a comment */ package MyPackage; import java.awt.*; class MyClass{} d. package MyPackage; class MyClass{} import java.awt.*;

f. Line 6

Which one line in the following code will not compile? 1. byte b = 5; 2. char c = '5'; 3. short s = 55; 4. int i = 555; 5. float f = 555.5f; 6. b = s; 7. i = c; 8. if (f > b) 9. f = i; a. Line 5 b. Line 2 c. Line 3 d. Line 7 e. Line 9 f. Line 6

c. Line 6 executes and line 4 does not.

Which one statement is true about the following code? 1. String s1 = "abc" + "def"; 2. String s2 = new String(s1); 3. if (s1 == s2) 4. System.out.println("== succeeded"); 5. if (s1.equals(s2)) 6. System.out.println(".equals() succeeded"); a. Lines 4 and 6 both execute. b. Line 4 executes and line 6 does not. c. Line 6 executes and line 4 does not. d. Neither line 4 nor line 6 executes.

a. There will be a compiler error, because class Greebo does not correctly implement the Runnable interface.

Which one statement is true concerning the following code? 1. class Greebo extends java.util.Vector implements Runnable { 2. 3. public void run(String message) { 4. System.out.println("in run() method: " + message); 5. 6. } 7. } 8. 9. class GreeboTest { 10. public static void main(String args[]) { 12. Greebo g = new Greebo(); 13. Thread t = new Thread(g); 14. t.start(); 15. } 16. } a. There will be a compiler error, because class Greebo does not correctly implement the Runnable interface. b. There will be a compiler error at line 13, because you cannot pass a parameter to the constructor of a Thread. c. The code will compile correctly but will crash with an exception at line 13. d. The code will compile correctly but will crash with an exception at line 14. e. The code will compile correctly and will execute without throwing any exceptions.

a. It always returns 0.

Which statement is true about the following method? int selfXor(int i) { return i ^ i; } a. It always returns 0. b. It always returns 1. c. It always an int where every bit is 1. d. The returned value varies depending on the argument.

b. An error at run time

You want to find out the value of the last element of an array. You write the following code. What will happen when you compile and run it.? public class MyAr{ public static void main(String argv[]){ int[] i = new int[5]; System.out.println(i[5]); } } a. An error at compile time b. An error at run time c. The value 0 will be output d. The string "null" will be output

b. JDBC

______ is a set of java API for executing SQL statements. a. ODBC b. JDBC c. JAVADB d. None of the others

a. File, File

(1) The java.io.... class makes it easier to write platform-independent code that examines and manipulates files. (2) The java.io..... class makes it easier to write platform-independent code that examines and manipulates folders. a. File, File b. File, Folder c. File, Directory d. File, Container

a. Both 1 and 2 are true

1.TCP is a connection-based protocol that provides a reliable flow of data between two computers. 2.TCP provides point-to-point channel for applications that require reliable communications: a. Both 1 and 2 are true b. Both 1 and 2 are false c. 1 is true, 2 is false d. 1 is false, 2 is true

c. public void logIt(String... msgs)

A programmer needs to create a logging method that can accept an arbitrary number of arguments. For example, it may be called in these ways: logIt("log message 1 "); logIt("log message2","log message3"); logIt("log message4", "log message5", "log message6"); Which declaration satisfies this requirement? a. public void logIt(String * msgs) b. public void logIt(String [] msgs) c. public void logIt(String... msgs) d. public void logIt(String msg1, String msg2, String msg3)

c. x = 13, a = 7, b = 8

After execution of the following code fragment, what are the values of the variables x, a, and b? 1. int x, a = 6, b = 7; 2. x = a++ + b++; a. x = 15, a = 7, b = 8 b. x = 15, a = 6, b = 7 c. x = 13, a = 7, b = 8 d. x = 13, a = 6, b = 7

c. x = 13, a = 7, b = 8

After execution of the following code fragment, what are the values of the variables x, a, and b? int x, a = 6, b = 7; x = a++ + b++; a. x = 15, a = 7, b = 8 b. x = 15, a = 6, b = 7 c. x = 13, a = 7, b = 8 d. x = 13, a = 6, b = 7

a. java.lang.Number

All of the numeric wrapper classes in the java.lang package are subclasses of the abstract class ....... a. java.lang.Number b. java.lang.Integer c. java.lang.Object d. java.lang.Wrapper

a. can contain all concrete methods.

An abstract class ......... a. can contain all concrete methods. b. must contain at least one abstract method. c. must contain all abstract method. d. can not contain any data field.


Set pelajaran terkait

Combo with "Mod 17 The Nonvisual Senses" and 5 others

View Set

Ethos Pathos and Logos Text Structure

View Set

Chapter 11 review 1, Computer User Support - Chapter 11, Chapter 11, A Guide to Customer User Support Quiz 11, Chapter 11 Quiz Tech Cust, Tech Support Admin. Ch. 11, Tech Sup Chapter 11

View Set

RIM_10_Vital Records and Business Continuity (Class)

View Set

ACCA F4 - Question Bank - 5. Capital & financing

View Set