Java 2

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

a

QN=100(305) MVC is short call of a. Model-View-Controller b. Multiple-View-Controller c. Metal-View-Controller

d

QN=51 (113) Given the following code, and making no other changes, which combination of access modifiers (public, protected, or private) can legally be placed before aMethod() on line 3 and be placed before aMethod() on line 8? (Choose one.) 1. class SuperDuper 2. { 3. void aMethod() { } 4. } 5. 6. class Sub extends SuperDuper 7. { 8. void aMethod() { } 9. } a. line 3: public; line 8: private b. line 3: protected; line 8: private c. line 3: default; line 8: private d. line 3: private; line 8: protected e. line 3: public; line 8: protected

abd

QN=52(187) Given the following code, which of the following will compile? (Choose three.) enum Spice { NUTMEG, CINNAMON, CORIANDER, ROSEMARY; } a. Spice sp = Spice.NUTMEG; Object ob = sp; b. Spice sp = Spice.NUTMEG; Object ob = (Object)sp; c. Object ob = new Object(); Spice sp = ob d. Object ob = new Object(); Spice sp = (Spice)ob; e. String ob = new String(); Spice sp = ob;

ab

QN=53 (224) Given the following: List<String> names = new ArrayList<String>(); which of the following are legal? (Choose two.) a. Iterator<String> iter = names.iterator(); b. for (String s:names) c. while (String s:names)

f

QN=54(1524) Given: 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. } What is the result? (Choose one.) 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.

d

QN=55(1407) Given: public class Bar { public static void main(String [] args) { int x =5; boolean b1 = true; boolean b2 = false; if((x==4) && !b2) System.out.print("l "); System.out.print("2 "); if ((b2 = true) && b1) System.out.print("3"); } } What is the result? (Choose one.) a. 2 b. 3 c. 1 2 d. 2 3 e. 1 2 3 f. Compilation fails.

a

QN=56(1418) Given: 1. public interface A { 2. String DEFAULT_GREETING = "Hello World"; 3. public void method1(); 4. } A programmer wants to create an interface called B that has A as its parent. Which interface declaration is correct? (Choose one.) a. public interface B extends A { } b. public interface B implements A {} c. public interface B instanceOf A {} d. public interface B inheritsFrom A { }

bd

QN=57(1420) Given: 10. abstract public class Employee { 11. protected abstract double getSalesAmount(); 12. public double getCommision() { 13. return getSalesAmount() * 0.15; 14. } 15. } 16. class Sales extends Employee { 17. // insert method here 18. } Which two methods, inserted independently at line 17, correctly complete the Sales class? (Choose two.) a. double getSalesAmount() { return 1230.45; } b. public double getSalesAmount() { return 1230.45; } c. private double getSalesAmount() { return 1230.45; } d. protected double getSalesAmount() { return 1230.45; }

bcd

QN=58 (1530)Given: 10. class MakeFile { 11. public static void main(String[] args) { 12. try { 13. File directory = new File("d"); 14. File file = new File(directory,"f"); 15. if(!file.exists()) { 16. file.createNewFile(); 17. } 18. }catch (IOException e) { 19. e.printStackTrace (); 20. } 21. } 22. } The current directory does NOT contain a directory named "d." Which three are true? (Choose three.) a. Line 16 is never executed. b. An exception is thrown at runtime. c. Line 13 creates a File object named "d." d. Line 14 creates a File object named "f.' e. Line 13 creates a directory named "d" in the file system. f. Line 16 creates a directory named "d" and a file 'f' within it in the file system.

d

QN=59 (1415)Given: 10. class Nav{ 11. public enum Direction { NORTH, SOUTH, EAST, WEST } 12. } 13. public class Sprite{ 14. // insert code here 15. } Which code, inserted at line 14, allows the Sprite class to compile? (Choose one.) a. Direction d = NORTH; b. Nav.Direction d = NORTH; c. Direction d = Direction.NORTH; d. Nav.Direction d = Nav.Direction.NORTH;

c

QN=60(1416) Given: 10. interface Foo { int bar(); } 11. public class Sprite { 12. public int fubar( Foo foo) { return foo.bar(); } 13. public void testFoo() { 14. fubar( 15. // insert code here 16. ); 17. } 18. } Which code, inserted at line 15, allows the class Sprite to compile? (Choose one.) a. Foo { public int bar() { return 1; } } b. new Foo { public int bar() { return 1; } } c. new Foo() { public int bar(){return 1; } } d. new class Foo { public int bar() { return 1; } }

a

QN=61(1528) Given: 10. public class ClassA { 11. public void count(int i) { 12. count(++i); 13. } 14. } And: 20. ClassA a = new ClassA(); 21. a.count(3); Which exception or error should be thrown by the virtual machine? (Choose one.) a. StackOverflowError b. NullPointerException c. NumberFormatException d. IllegalArgumentException e. ExceptionlnlnitializerError

c

QN=62 (1419)Given: 11. public abstract class Shape { 12. int x; 13. int y; 14. public abstract void draw(); 15. public void setAnchor(int x, int y) { 16. this.x = x; 17. this.y = y; 18. } 19. } and a class Circle that extends and fully implements the Shape class. Which is correct? (Choose one.) a. Shape s = new Shape(); s.setAnchor(10,10); s.draw(); b. Circle c = new Shape(); c.setAnchor(10,10); c.draw(); c. Shape s = new Circle(); s.setAnchor(10,10); s.draw(); d. Shape s = new Circle(); s->setAnchor(10,10); s->draw(); e. Circle c = new Circle(); c.Shape.setAnchor(10,10); c.Shape.draw();

a

QN=63 (1425) Given: 11. public static void main(String[] args) { 12. Object obj =new int[] { 1,2,3 }; 13. int[] someArray = (int[])obj; 14. for (int i: someArray) System.out.print(i +" "); 15. } What is the result? (Choose one.) a. 1 2 3 b. Compilation fails because of an error in line 12. c. Compilation fails because of an error in line 13. d. Compilation fails because of an error in line 14. e. A ClassCastException is thrown at runtime.

c

QN=64 (1526)Given: 11. public static void main(String[] args) { 12. try { 13. args=null; 14. args[0] = "test"; 15. System.out.println(args[0]); 16. }catch (Exception ex) { 17. System.out.println("Exception"); 18. }catch (NullPointerException npe) { 19. System.out.println("NullPointerException"); 20. } 21. } What is the result? (Choose one.) a. test b. Exception c. Compilation fails. d. NullPointerException

b

QN=65 (1421)Given: 11. public static void parse(String str) { 12. try { 13. float f= Float.parseFloat(str); 14. } catch (NumberFormatException nfe) { 15. f = 0; 16. } finally { 17. System.out.println(f); 18. } 19. } 20. public static void main(String[] args) { 21. parse("invalid"); 22. } What is the result? (Choose one.) a. 0.0 b. Compilation fails. c. A ParseException is thrown by the parse method at runtime. d. A NumberFormatException is thrown by the parse method at runtime.

d

QN=66(1532) Given: 11. String test = "This is a test"; 12. String[] tokens = test.split("\s"); 13. System.out.println(tokens.length); What is the result? (Choose one.) a. 0 b. 1 c. 4 d. Compilation fails. e. An exception is thrown at runtime.

c

QN=67 (1519)Given: 12. public class AssertStuff { 14. public static void main(String [] args) { 15. int x= 5; 16. int y= 7; 18. assert (x > y): "stuff"; 19. System.out.println("passed"); 20. } 21. } And these command line invocations: java AssertStuff java -ea AssertStuff What is the result? (Choose one.) a. passed stuff b. stuff passed c. passed An AssertionError is thrown with the word "stuff" added to the stack trace. d. passed An AssertionError is thrown without the word "stuff" added to the stack trace. e. passed An AssertionException is thrown with the word "stuff" added to the stack trace. f. passed An AssertionException is thrown without the word "stuff" added to the stack trace.

d

QN=68 (1516)Given: 12. public class Test { 13. public enum Dogs {collie, harrier}; 14. public static void main(String [] args) { 15. Dogs myDog = Dogs.collie; 16. switch (myDog) { 17. case collie: 18. System.out.print("collie "); 19. case harrier: 20. System.out.print("harrier "); 21. } 22. } 23. } What is the result? (Choose one.) a. collie b. harrier c. Compilation fails. d. collie harrier e. An exception is thrown at runtime.

d

QN=69(1414) Given: 13. public class Pass { 14. public static void main(String [] args) { 15. int x = 5; 16. Pass p = new Pass(); 17. p.doStuff(x); 18. System.out.print(" main x = "+ x); 19. } 20. 21. void doStuff(int x) { 22. System.out.print("doStuff x = "+ x++); 23. } 24. } What is the result? (Choose one.) a. Compilation fails. b. An exception is thrown at runtime. c. doStuff x = 6 main x = 6 d. doStuff x = 5 main x = 5 e. doStuff x = 5 main x = 6 f. doStuff x = 6 main x = 5

d

QN=70(1413) Given: 13. public class Pass { 14. public static void main(String [] args) { 15. int x = 5; 16. Pass p = new Pass(); 17. p.doStuff(x); 18. System.out.print(" main x = "+ x); 19. } 20. 21. void doStuff(int x) { 22. System.out.print("doStuffx = "+ x++); 23. } 24. } What is the result? (Choose one.) a. Compilation fails. b. An exception is thrown at runtime. c. doStuffx = 6 main x = 6 d. doStuffx = 5 main x = 5 e. doStuffx = 5 main x = 6 f. doStuffx = 6 main x = 5

c

QN=71 (1409)Given: 20. public class CreditCard { 22. private String cardlD; 23. private Integer limit; 24. public String ownerName; 26. public void setCardlnformation(String cardlD, 27. String ownerName, 28. Integer limit) { 29. this.cardlD = cardlD; 30. this.ownerName = ownerName; 31. this.limit = limit; 32. } 33. } Which is true? (Choose one.) a. The class is fully encapsulated. b. The code demonstrates polymorphism. c. The ownerName variable breaks encapsulation. d. The cardlD and limit variables break polymorphism. e. The setCardlnformation method breaks encapsulation.

b

QN=72 (1412)Given: 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. } What is the result? (Choose one.) a. Compilation fails due to an error in line 23. b. Compilation fails due to an error in line 29. c. A ClassCastException occurs in line 29. d. A ClassCastException occurs in line 31. e. The value of all four objects prints in natural order.

bce

QN=73(1408) Given: 31. // some code here 32. try { 33. // some code here 34. } catch (SomeException se) { 35. // some code here 36. } finally { 37. // some code here 38. } Under which three circumstances will the code on line 37 be executed? (Choose three.) a. The instance gets garbage collected. b. The code on line 33 throws an exception. c. The code on line 35 throws an exception. d. The code on line 31 throws an exception. e. The code on line 33 executes successfully.

d

QN=74(1522) Given: 33. try { 34. // some code here 35. }catch (NullPointerException e1) { 36. System.out.print("a"); 37. }catch (RuntimeException e2) { 38. System.out.print("b"); 39. } finally { 40. System.out.print("c"); 41. } What is the result if a NullPointerException occurs on line 34? (Choose one.) a. c b. a c. ab d. ac e. bc f. abc

b

QN=75(1422) Given: 55. int []x= {1, 2,3,4, 5}; 56. int y[] =x; 57. System.out.println(y[2]); Which is true? (Choose one.) a. Line 57 will print the value 2. b. Line 57 will print the value 3. c. Compilation will fail because of an error in line 55. d. Compilation will fail because of an error in line 56.

be

QN=76(1518) Given: 8. public class test { 9. public static void main(String [] a) { 10. assert a.length == 1; 11. } 12.} Which two will produce an AssertionError? (Choose two.) a. java test b. java -ea test c. java test file1 d. java -ea test file1 e. java -ea test file1 file2 f. java -ea:test test file1

be

QN=77(1529) Given: 1. public class TestString3 { 2. public static void main(String[] args) { 3. // insert code here 5. System.out.println(s); 6. } 7. } Which two code fragments, inserted independently at line 3, generate the output 4247? (Choose two.) a. String s = "123456789"; s = (s-"123").replace(1,3,"24") - "89"; b. StringBuffer s = new StringBuffer("123456789"); s.delete(0,3).replace( 1,3, "24").delete(4,6); c. StringBuffer s = new StringBuffer("123456789"); s.substring(3,6).delete( 1 ,3).insert( 1, "24"); d. StringBuilder s = new StringBuilder("123456789"); s.substring(3,6).delete( 1 ,2).insert( 1, "24"); e. StringBuilder s = new StringBuilder("123456789"); s.delete(0,3).delete( 1 ,3).delete(2,5).insert( 1, "24");

b

QN=78(1514) 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 instance of the Point class defined in Line? (Choose one.) a. Point p = new Point(); b. Line.Point p = new Line.Point(); c. The Point class cannot be instatiated at line 15. d. Line l = new Line() ; Point p = new l.Point();

bd

QN=79(1406) Given: 10. public class Bar { 11. static void foo(int...x) { 12. // insert code here 13. } 14. } Which two code fragments, inserted independently at line 12, will allow the class to compile? (Choose two.) a. foreach(x) System.out.println(z); b. for(int z : x) System.out.println(z); c. while( x.hasNext()) System.out.println( x.next()); d. for( int i=0; i< x.length; i++ ) System.out.println(x[i]);

abd

QN=80(1405) Given: 11. public interface Status { 12. /* insert code here */ int MY_VALUE = 10; 13. } Which three are valid on line 12? (Choose three.) a. final b. static c. native d. public e. protected f. abstract

b

QN=81 (1523) Given: class A { public void process() { System.out.print("A "); } public static void main(String[] args) { try { ((A)new B()).process(); } catch (Exception e) { System.out.print("Exception "); } } } class B extends A { public void process() throws RuntimeException { super.process(); if (true) throw new RuntimeException(); System.out.print("B"); } } What is the result? (Choose one.) a. Exception b. A Exception c. A Exception B d. A B Exception e. Compilation fails because of an error in line: public void process() throws RuntimeException f. Compilation fails because of an error in line: try { ((A)new B()).process(); }

d

QN=82(209) How can you ensure that multithreaded code does not deadlock? (Choose one.) a. Synchronize access to all shared variables. b. Make sure all threads yield from time to time. c. Vary the priorities of your threads. d. There is no single technique that can guarantee non-deadlocking code.

a

QN=83 (52) How can you force garbage collection of an object? (Choose one.) a. Garbage collection cannot be forced. b. Call System.gc(). c. Call System.gc(), passing in a reference to the object to be garbage-collected. d. Call Runtime.gc(). e. Set all references to the object to new values (null, for example).

d

QN=84(208) How do you prevent shared data from being corrupted in a multithreaded environment? (Choose one.) a. Mark all variables as synchronized. b. Mark all variables as volatile. c. Use only static variables. d. Access the variables only via synchronized methods.

a

QN=85 (236) How do you use the File class to list the contents of a directory? (Choose one.) a. String[] contents = myFile.list(); b. File[] contents = myFile.list(); c. StringBuilder[] contents = myFile.list(); d. The File class does not provide a way to list the contents of a directory.

b

QN=86(237) How many bytes does the following code write to file dest? (Choose one.) 1. try { 2. FileOutputStream fos = newFileOutputStream("dest"); 3. DataOutputStream dos = new DataOutputStream(fos); 4. dos.writeInt(3); 5. dos.writeFloat(0.0001f); 6. dos.close(); 7. fos.close(); 8. } 9. catch (IOException e) { } a. 2 b. 8 c. 12 d. 16 e. The number of bytes depends on the underlying system.

a

QN=87 (204) How many locks does an object have? (Choose one.) a. One b. One for each method c. One for each synchronized method d. One for each non-static synchronized method

d

QN=88(48) If all three top-level elements occur in a source file, they must appear in.which order? (Choose one.) a. Imports, package declarations, classes/interfaces/enums b. Classes/interfaces/enums, imports, package declarations c. Package declaration must come first; order for imports and class/interfaces/enum definitions is not significant d. Package declaration, imports, class/interface/enum definitions. e. Imports must come first; order for package declarations and class/interface/enum definitions is not significant

b

QN=89(123) If class Y extends class X, the two classes are in different packages, and class X has a protected method called abby(), then any instance of Y may call the abby() method of any other instance of Y. a. True b. False

a

QN=90(197) If you attempt to compile and execute the following application, will it ever print out the message In xxx? 1. class TestThread3 extends Thread { 2. public void run() { 3. System.out.println("Running"); 4. System.out.println("Done"); 5. } 6. 7. private void xxx() { 8. System.out.println("In xxx"); 9. } 10. 11. public static void main(String args[]) { 12. TestThread3 ttt = new TestThread3(); 13. ttt.xxx(); 14. ttt.start(); 12. } 13. } a. Yes b. No

c

QN=91 (1877) If you need a Set implementation that provides value-ordered iteration, which class should you use? (Choose one.) a. HashSet b. LinkedHashSet c. TreeSet

a

QN=92(1875) In order for objects in a List to be sorted, those objects must implement which interface and method? (Choose one.) 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

a

QN=93(218) In the following code fragment, after execution of line 1, sbuf references an instance of the StringBuffer class. After execution of line 2, sbuf still references the same instance. 1. StringBuffer sbuf = new StringBuffer("FPT"); 2. sbuf.append("-University"); a. True b. False

a

QN=94 (217) In the following code fragment, after execution of line 1, sbuf references an instance of the StringBuffer class. After execution of line 2, sbuf still references the same instance. 1. StringBuffer sbuf = new StringBuffer("FPT"); 2. sbuf.insert(3, "-University"); a. True b. False

e

QN=95(130) In the following code, what are the possible types for variable result? (Choose the most complete true 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

d

QN=96(7266) Interface helps manage the connection between a Java program and a database. a. ResultSet b. DriverManager c. Statement d. Connection

a

QN=97(76) Is it possible to define a class called Thing so that the following method can return true under certain circumstances? boolean weird(Thing s) { Integer x = new Integer(5); return s.equals(x); } a. Yes b. No

a

QN=98 ( 205) Is it possible to write code that can execute only if the current thread owns multiple locks? a. Yes b. No

b

QN=99(301) JDBC supports and models. a. Single-tier and two-tier b. Two-tier and three-tier c. Three-tier and four-tier d. None of the others


संबंधित स्टडी सेट्स

Chapter 62: Managements of Patients with Burn Injury (Brunner)

View Set

Fizika II - instant bukó kérdések

View Set

Chapter 47: Management of Patients With Gastric and Duodenal Disorders

View Set

Jason Dion's CySA+ Practice Exam 1

View Set

Chapter 20: Cell Communities: Tissues, Stem Cells and Cancer

View Set

Chapter 10: Supply Chain Security

View Set

Living Environment - Multiple Choice

View Set

Common Skin Conditions (unfinished)

View Set

66 Books of the Bible (5,12,5,5,12)

View Set