0
Alien head

programming languages Online Quiz - 52

Description: programming languages Online Quiz - 52
Number of Questions: 20
Created by:
Tags: programming languages
  1. import java.util.*; 2. 3. public class LetterASort{ 4. public static void main(String[] args) { 5. ArrayList strings = new ArrayList(); 6. strings.add("aAaA"); 7. strings.add("AaA"); 8. strings.add("aAa"); 9. strings.add("AAaa"); 10. Collections.sort(strings); 11. for (String s : strings) { System.out.print(s + " "); } 12. } 13. } What is the result?
  1. Compilation fails.

  2. aAaA aAa AAaa AaA

  3. AAaa AaA aAa aAaA

  4. AaA AAaa aAaA aAa

  5. aAa AaA aAaA AAaa

  6. An exception is thrown at runtime

Answer: 3
  1. public class Threads5 { 2. public static void main (String[] args) { 3. new Thread(new Runnable() { 4. public void run() { 5. System.out.print("bar"); 6. }}).start(); 7. } 8. } What is the result?
  1. Compilation fails.

  2. An exception is thrown at runtime.

  3. The code executes normally and prints "bar".

  4. The code executes normally, but nothing prints.

Answer: 3
  1. rbo = new ReallyBigObject(); 12. // more code here 13. rbo = null; 14. /* insert code here */ Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object rbo?
  1. System.gc();

  2. Runtime.gc();

  3. System.freeMemory();

  4. Runtime.getRuntime().growHeap();

  5. Runtime.getRuntime().freeMemory();

Answer: 1

Given: 11.classA { 12. public void process() { System.out.print(”A “); } } 13. class B extends A { 14. public void process() throws RuntimeException { 15. super.process(); 16. if (true) throw new RuntimeException(); 17. System.out.print(“B”); }} 18. public static void main(String[] args) { 19. try { ((A)new B()).process(); } 20. catch (Exception e) { System.out.print(”Exception “); } 21. } What is the result?

  1. Exception

  2. A Exception

  3. A Exception B

  4. A B Exception

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

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

Answer: 2

You read the following statement in a Java program that compiles and executes. submarine.dive(depth); What can you say for sure?

  1. depth must be an int

  2. dive must be a method.

  3. dive must be the name of an instance field.

  4. submarine must be the name of a class

  5. submarine must be a method.

Answer: 2

class Eggs { int doX(Long x, Long y) { return 1; } int doX(long... x) { return 2; } int doX(Integer x, Integer y) { return 3; } int doX(Number n, Number m) { return 4; } public static void main(String[] args) { new Eggs().go(); } void go() { short s = 7; System.out.print(doX(s,s) + " "); System.out.println(doX(7,7)); } } What is the result?

  1. 1 1

  2. 2 1

  3. 3 1

  4. 4 1

  5. 2 3

  6. 4 3

Answer: 6

public class A { private int counter=0; public static int getInstanceCount() { return counter; } public A() { counter++; } } Given this code from Class B: 25. A a1 = new A(); 26. A a2 = new A(); 27. A a3 = new A(); 28. System.out.println(A.getInstanceCount()); What is the result?

  1. Compilation of class A fails.

  2. Line 28 prints the value 3 to System.out.

  3. Line 28 prints the value 1 to System.out

  4. A runtime error occurs when line 25 executes

  5. Compilation fails because of an error on line 28

Answer: 1

Which are valid declarations? (Choose all that apply)

  1. int $x

  2. int 123

  3. int _123

  4. int #dim

  5. int %percent

  6. int central_sales_region_Summer_2005_gross_sales

Answer: 1,3,6

Casting occurs commonly between numeric types

  1. True

  2. False

Answer: 1

Which of the following are methods of the Thread class.

  1. public void run()

  2. public void start()

  3. public void exit()

  4. public final void setAccess()

  5. public final void setPriority(int priNbr)

  6. public final int getPriority()

Answer: 1,2,5,6

Select three correct statements.

  1. ) A static method may override another static method

  2. A static method cannot override a non-static method

  3. non-static method cannot override a static method

  4. A non-static method may be overloaded by a static method

  5. A synchronized method cannot be overridden

Answer: 2,3,4

How old are you 7

  1. 1

  2. 2

  3. 3

  4. 4

Answer: 1

How old are you 6

  1. 1

  2. 2

  3. 3

  4. 4

Answer: 4

How old are you 5

  1. 1

  2. 2

  3. 3

  4. 4

Answer: 3

How old are you 4

  1. 1

  2. 2

  3. 3

  4. 4

Answer: 2

How old are you 3

  1. 1

  2. 2

  3. 3

  4. 4

Answer: 4

How old are you 2

  1. 1

  2. 2

  3. 3

  4. 4

Answer: 3

How old are you 1

  1. 1

  2. 2

  3. 3

  4. 4

Answer: 1,2,3,4

How old are you

  1. 1

  2. 2

  3. 3

  4. 4

Answer: 1,2,3,4

Select three correct statements

  1. A static method may override another static method

  2. A static method cannot override a non-static method

  3. A non-static method cannot override a static method

  4. A non-static method may be overloaded by a static method

  5. A synchronized method cannot be overridden

Answer: 1,2,3,4,5
+ View questions