Hide all answers
Hide all answers
View all answers
View all answers
Print
Try the Quiz
Questions about arrays and classes in the java.lang package. |
1. Which of the following statements are valid array declaration? (A) int number(); (B) float average[]; (C) double[] marks; (D) counter int[]; (B) & (C) (A)
(A) & (C)
(D)
Answer: (B) & (C) 2. Consider the following code int number[] = new int[5]; After execution of this statement, which of the following are true? (A) number[0] is undefined (B) number[5] is undefined (C) number[4] is null (D) number[2] is 0 (E) number.length() is 5 (A) & (E)
(B), (D) & (E) (C) & (E)
(E)
Answer: (B), (D) & (E) 3. What will be the content of array variable table after executing the following code? for(int i = 0; i < 3; i + +) for(int j = 0; j < 3; j + +) if(j = i) table[i][j] = 1; else table[i][j] = 0; 0 0 0 0 0 0 0 0 0
1 0 0 0 1 0 0 0 1 1 0 0 1 1 0 1 1 1
0 0 1 0 1 0 1 0 0
Answer: 1 0 0 0 1 0 0 0 1
4. Which of the following classes are available in the java.lang package? (A) Stack (B) Object (C) Math (D) Random (E) String (F) StringBuffer (G) Vector (B), (C) & (E)
(B), (E) & (F)
(C), (E) & (F)
(A), (B), (C), (E) & (F)
(B), (C), (E) & (F)
Answer: (B), (C), (E) & (F) 5. Which of the following are the wrapper classes? (A) Random (B) Byte (C) Vector (D) Integer (E) Short (F) Double (G) String (B), (D) & (E)
(B), (D) & (F)
(B), (D), (E) & (F) (D), (E) & (F)
(A), (B), (D), (E) & (F)
Answer: (B), (D), (E) & (F) 6. Which of the following contain error? (A) int x[] = int[10]; (B) int[] y = new int[5]; (C) float d[] = (A), (D) & (E)
(A), (E) & (F)
(D), (E) & (F)
(A), (D) & (F) (A), (B), (D), (E) & (F)
Answer: (A), (D) & (F) 7. Which of the following methods belong to the String class? length()
compareTo()
equals()
substring()
All of these None of these
Answer: All of these 8. Given the code String s1 = "yes"; String s2 = "yes"; String s3 = new String(s1); Which of the following would equate to true? (A) s1 == s2 (B) s1 = s2 (C) s3 == s1 (D) s1.equals(s2) (E) s3.equals(s1) (A), (C) & (E)
(A), (B) & (C)
(C), (D) & (E)
(A), (D) & (E) (D) & (E)
Answer: (A), (D) & (E) 9. Suppose that s1 and s2 are two strings. Which of the statements or expressions are valid? (A) String s3 = s1 + s2; (B) String s3 = s1 - s2; (C) s1 <= s2 (D) s1.compareTo(s2); (E) int m = s1.length(); (A), (D) & (E) (A), (C) & (E)
(A), (B) & (C)
(C), (D) & (E)
(D) & (E)
Answer: (A), (D) & (E) 10. Given the code String s = new String("abc"); Which of the following calls are valid? (A) s.trim() (B) s.replace('a', 'A') (C) s.substring(3) (D) s.toUppercase() (E) s.setCharAt(1,'A') (F) s.append("xyz") (A), (C), (D) & (E)
(A), (B) & (C)
(C), (D) & (E)
(D) & (E)
(A), (B), (C) & (D)
Answer: (A), (B), (C) & (D) 11. The methods wait() and notify() are defined in java.lang.String
java.lang.Runnable
java.lang.Thread
java.lang.Object java.lang.ThreadGroup
Answer: java.lang.Object 12. Which of the following statements are true? (A) A Java monitor must either extend Thread or implement Runnable. (B) The sleep() method should be enclosed in try ... catch block. (C) The yield() method should be enclosed in try ... catch block. (D) A thread can be temporarily suspended from running by using the wait() method. (E) A suspended thread using suspend() method can be revived using the resume() method. (A), (B), (D) & (E)
(A), (B) & (D)
(C), (D) & (E)
(B), (D) & (E) (D) & (E)
Answer: (B), (D) & (E) 13. Given the following code: class Base { int x = 10; } class Derived extends Base { int x = 20; }
Base b = new Base(); Derived d = new Derived ( ); Base bd = new Derived(); The statement System.out.println(b.x + " " + d.x + " " + bd.x); will produce the output 10 20 10 10 20 20
20 10 20
20 20 10
Answer: 10 20 10 14. Given the class definitions class Base { void display () { System.out.println("Base"); } } class Derived extends Base { void display () { System.out.println("Derived"); } } and objects Base b = new Base(); Derived d = new Derived(); Base bd = new Derived;
then the print statements System.out.print(b.display() + " "); System.out.print(d.display() + " "); System.out.print(bd.display() + " "); System.out.println(); will display: Base Base Derived
Base Derived Base
Base Derived Derived Derived Derived Derived
Answer: Base Derived Derived 15. When we implement the Runnable interface, we must define the method start()
init()
resume()
main()
run()
Answer: run()
Try the Quiz : Java Programming : Arrays and java.lang.* : Multiple Choice
|