Студопедия

КАТЕГОРИИ:

АвтомобилиАстрономияБиологияГеографияДом и садДругие языкиДругоеИнформатикаИсторияКультураЛитератураЛогикаМатематикаМедицинаМеталлургияМеханикаОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРелигияРиторикаСоциологияСпортСтроительствоТехнологияТуризмФизикаФилософияФинансыХимияЧерчениеЭкологияЭкономикаЭлектроника



Click the Exhibit button. 12. ClassB classB = new ClassB();

Читайте также:
  1. At a chemical exhibition
  2. CLICK HERE TO SIGN UP
  3. Click the Exhibit button.
  4. Click the Exhibit button.
  5. Click the Exhibit button.
  6. Click the Exhibit button.
  7. Click the Exhibit button.
  8. Fairs and exhibitions
  9. Sub CommandButton1_Click()

10. public class ClassA {

11. public void methodA() {

12. ClassB classB = new ClassB();

13. classB.getValue();

14. }

15. }

And:

20. class ClassB {

21. public ClassC classC;

22.

23. public String getValue() {

24. return classC.getValue();

25. }

26. }

And:

30. class ClassC {

31. public String value;

32.

33. public String getValue() {

34. value = "ClassB";

35. return value;

36. }

37. }

Given:

ClassA a = new ClassA(); a.methodA();

What is the result?

A. Compilation fails.

B. ClassC is displayed.

C. The code runs with no output.

D. An exception is thrown at runtime.

91. Given:

10. public class Foo {

11. static int[] a;

12. static { a[0]=2; }

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

14. }

Which exception or error will be thrown when a programmer attempts to run this code?

A. java.lang. StackOverflowError

B. java.lang.IllegalStateException

C. java.lang.ExceptionlnlnitializerError

D. java.lang.ArraylndexOutOfBoundsException

 

92. 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?

A. StackOverflowError

B. NullPointerException

C. NumberFormatException

D. IllegalArgumentException

E. ExceptionlnlnitializerError

 

93. Given:

1. public class Boxer1 {

2. Integer i;

3. int x;

4. public Boxer1(int y) {

5. x=i+y;

6. System.out.println(x);

7. }

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

9. new Boxer1(new Integer(4));

10. }

11. }

What is the result?

A. The value "4" is printed at the command line.

B. Compilation fails because of an error in line 5.

C. Compilation fails because of an error in line 9.

D. A NullPointerException occurs at runtime.

E. A NumberFormatException occurs at runtime.

F. An IllegalStateException occurs at runtime.

 

94. Given:

1. public class TestString 1 {

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

3. String str = "420";

4. str += 42;

5. System.out.print(str);

6. }

7. }

 

What is the output?



A. 42 B. 420

C. 462 D. 42042

E. Compilation fails. F. An exception is thrown at runtime.

95. Given:

11. class Converter {

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

13. Integer i = args[0];

14. int j = 12;

15. System.out.println("It is " + (j==i) + "that j==i.");

16. }

17. }

What is the result when the programmer attempts to compile the code and run it with the command java Converter 12?

A. It is true that j==i.

B. It is false that j==i.

C. An exception is thrown at runtime.

D. Compilation fails because of an error in line 13

96. Given this method in a class:

21. public String toString() {

22. StringBuffer buffer = new StringBuffer();

23. buffer.append('<');

24. buffer.append(this.name);

25. buffer.append('>');

26. return buffer.toString();

27. }

Which is true?

A. This code is NOT thread-safe.

B. The programmer can replace StringBuffer with StringBuilder with no other changes.

C. This code will perform well and converting the code to use StringBuilder will not enhance the performance.

D. This code will perform poorly. For better performance, the code should be rewritten: return "<"+ this.name + ">";



 

97. Given:

1. public class MyLogger {

2. private StringBuilder logger = new StringBuuilder();

3. public void log(String message, String user) {

4. logger.append(message);

5. logger.append(user);

6. }

7. }

The programmer must guarantee that a single MyLogger object works properly for a multi-threaded system. How must this code be changed to be thread-safe?

A. synchronize the log method

B. replace StringBuilder with StringBuffer

C. No change is necessary, the current MyLogger code is already thread-safe.

D. replace StringBuilder with just a String object and use the string concatenation (+=) within the log method

 

98. Given:

11. public String makinStrings() {

12. String s = "Fred";

13. s = s + "47";

14. s = s.substring(2, 5);

15. s = s.toUpperCase();

16. return s.toString();

17. }

How many String objects will be created when this method is invoked?

A. 1

B. 2

C. 3

D. 4

E. 5

F. 6

 

 

99. 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");

 

100. Given:

11. public class Yikes {

13. public static void go(Long n) {System.out.println("Long ");}

14. public static void go(Short n) {System.out.println("Short ");}

15. public static void go(int n) {System.out.println("int ");}

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

17. short y= 6;

18. long z= 7;

19. go(y);

20. go(z);

21. }

22. }

 

What is the result?

A. int Long

B. Short Long

C. Compilation fails.

D. An exception is thrown at runtime.

 

101. Given:

12. public class Wow {

13. public static void go(short n) {System.out.println("short"); }

14. public static void go(Short n) {System.out.println("SHORT");}

15. public static void go(Long n) {System.out.println(" LONG"); }

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

17. Short y= 6;

18. int z=7;

19. go(y);

20. go(z);

21. }

22. }

What is the result?

A. short LONG

B. SHORT LONG

C. Compilation fails.

D. An exception is thrown at runtime.

 

 

102. 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.

G. Line 14 creates a file named 'f' inside of the directory named "d" in the file system.

 

103. When comparing java.io.BufferedWriter to java.io.FileWriter, which capability exists as a method in only one of the two?

A. closing the stream

B. flushing the stream

C. writing to the stream

D. marking a location in the stream

E. writing a line separator to the stream

104. Given:

12. import java.io.*;

13. public class Forest implements Serializable {

14. private Tree tree = new Tree();

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

16. Forest f= new Forest();

17. try {

18. FileOutputStream fs = new FileOutputStream("Forest.ser");

19. ObjectOutputStream os = new ObjectOutputStream(fs);

20. os.writeObject(f); os.close();

21. } catch (Exception ex) { ex.printStackTrace(); }

22. }}

23.

24. class Tree { }

What is the result?

A. Compilation fails.

B. An exception is thrown at runtime.

C. An instance of Forest is serialized.

D. A instance of Forest and an instance of Tree are both serialized.

 

 


Дата добавления: 2015-09-13; просмотров: 8; Нарушение авторских прав


<== предыдущая лекция | следующая лекция ==>
Click the Exhibit button. 7. } catch (TestException te) { | Click the Exhibit button. 2. public class Foo implements Serializable {
lektsii.com - Лекции.Ком - 2014-2018 год. (0.024 сек.) Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав
Главная страница Случайная страница Контакты