0
Alien head

programming languages Online Quiz - 100

Description: programming languages Online Quiz - 100
Number of Questions: 20
Created by:
Tags: programming languages
Attempted 0/20 Correct 0 Score 0

Which of the following statements are true?

  1. The return type for a method can be any Java type, including void

  2. An important principal of object oriented programming is implementation hiding

  3. When you perform mathematical calculations on the unlike data type, java will perform a implicit conversion to unify the types

  4. All the Above


Correct Option: D

Which two are true about has-a and is-a relationships? (Choose two.)

  1. Inheritance represents an is-a relationship.

  2. Inheritance represents a has-a relationship.

  3. Interfaces must be used when creating a has-a relationship.

  4. Instance variables can be used when creating a has-a relationship.


Correct Option: A,D

Given: 11. public class Counter { 12. public static void main(String[] args) { 13. int numArgs = /* insert code here */; 14. } 15. } and the command line: java Counter one fred 42 Which code, inserted at line 13, captures the number of arguments passed into the program?

  1. args.count

  2. args.length

  3. args.count()

  4. args.length()


Correct Option: B

Given: 34. HashMap props = new HashMap(); 35. props.put(”key45”, “some value”); 36. props.put(”key12”, “some other value”); 37. props.put(”key39”, “yet another value”); 38. Set s = props.keySet(); 39. // insert code here What, inserted at line 39, will sort the keys in the props HashMap?

  1. Arrays.sort(s);

  2. s = new TreeSet(s);

  3. Collections.sort(s);

  4. s = new SortedSet(s);


Correct Option: B

Which two are true? (Choose two.)

  1. A finalizer may NOT be invoked explicitly.

  2. The finalize method declared in class Object takes no action.

  3. super.finalize() is called implicitly by any overriding finalize method.

  4. The finalize method for a given object will be called no more than

  5. The order in which finalize will be called on two objects is based on


Correct Option: B,D

foo and bar are public references available to many other threads. foo refers to a Thread and bar is an Object. The thread foo is currently executing bar.wait(). From another thread, which statement is the most reliable way to ensue that foo will stop executing wait()?

  1. foo.notify();

  2. bar.notify();

  3. foo.notifyAll();

  4. Thread.notify();

  5. bar.notiFYAll();

  6. Object.notify();


Correct Option: E

Given: 1. public class TestOne { 2. public static void main (String[] args) throws Exception { 3. Thread.sleep(3000); 4. System.out.println(”sleep”); 5. } 6. } What is the result?

  1. Compilation fails.

  2. An exception is thrown at runtime.

  3. The code executes normally and prints “sleep”.

  4. The code executes normally, but nothing is printed.


Correct Option: C

Given: 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.


Correct Option: C

Given: 11. public static void test(String str) { 12. int check = 4; 13. if (check = str.length()) { 14. System.out.print(str.charAt(check -= 1) +“, “); 15. } else { 16. System.out.print(str.charAt(0) + “, “); 17. } 18. } and the invocation: 21. test(”four”); 22. test(”tee”); 23. test(”to”); What is the result?

  1. r, t, t,

  2. r, e, o,

  3. Compilation fails.

  4. An exception is thrown at runtime.


Correct Option: C

Which of the following is correct syntax for an Abstract class ?

  1. abstract double area() { }

  2. abstract double area()

  3. abstract double area();

  4. abstract double area(); { }


Correct Option: C

Which two are true? (Choose two.)

  1. An encapsulated, public class promotes re-use.

  2. Classes that share the same interface are always tightly

  3. An encapsulated class allows subclasses to overload methods, but

  4. An encapsulated class allows a programmer to change an


Correct Option: A,D

Given: 11. String test= “a1b2c3”; 12. String[] tokens = test.split(”\d”); 13. for(String s: tokens) System.out.print(s +“ “); What is the result?

  1. a b c

  2. 1 2 3

  3. a1b2c3

  4. Compilation fails


Correct Option: A

Given: 10. public class Foo implements java.io.Serializable { 11. private int x; 12. public int getX() { return x; } 12.publicFoo(int x){this.x=x; } 13. private void writeObject( ObjectOutputStream s) 14. throws IOException { 15. // insert code here 16. } 17. } Which code fragment, inserted at line 15, will allow Foo objects to be correctly serialized and deserialized?

  1. s.writeInt(x);

  2. s.serialize(x);

  3. s.writeObject(x);

  4. s.defaultWriteObject();


Correct Option: D

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?

  1. c

  2. a

  3. ab

  4. ac

  5. bc


Correct Option: D

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?

  1. collie

  2. harrier

  3. Compilation fails

  4. collie harrier


Correct Option: D

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?

  1. 1 2 3

  2. B. Compilation fails because of an error in line 12.

  3. B. Compilation fails because of an error in line 13.

  4. B. Compilation fails because of an error in line 14.


Correct Option: A

Which type of Statement can execute parameterized queries?

  1. PreparedStatement

  2. ParameterizedStatement

  3. ParameterizedStatement and CallableStatement

  4. All kinds of Statements (i.e. which implement a sub interface of Statement)


Correct Option: B

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?

  1. 0.0

  2. Compilation fails

  3. A ParseException is thrown by the parse method at runtime.

  4. A NumberFormatException is thrown by the parse method at


Correct Option: B

Given: 1. package sun.scjp; 2. public enum Color { RED, GREEN, BLUE } 1. package sun.beta; 2. // insert code here 3. public class Beta { 4. Color g = GREEN; 5. public static void main( String[] argv) 6. { System.out.println( GREEN); } 7. } The class Beta and the enum Color are in different packages. Which two code fragments, inserted individually at line 2 of the Beta declaration, will allow this code to compile? (Choose two.)

  1. import sun.scjp.Color.*;

  2. import static sun.scjp.Color.*;

  3. import sun.scjp.Color; import static sun.scjp.Color.*;

  4. import sun.scjp.; import static sun.scjp.Color.;

  5. import sun.scjp.Color; import static sun.scjp.Color.GREEN;


Correct Option: C,E

Which type of driver provides JDBC access via one or more ODBC drivers?

  1. Type 4 driver

  2. Type 3 driver

  3. Type 2 driver

  4. Type 1 driver


Correct Option: D
+ View questions