1. int x = 6; 2. double d = 7.7;
3. System.out.println((x>d) ? 99.9 : 9); a. 9 b. 9.0 c. 99.9
d. Nothing, an ArithmeticException is thrown at line 3.
Q47
Which of the following are legal methods for the String class ? a. length() b. toUpper() c. toUppercase() d. equals()
Q48
Consider the following 1. class A extends Integer { 2. int x = 0; 3. }
a. The code will compile correctly.
b. The code will not compile because Integer class is final.
c. The code will not compile because A class doesn't have a constructor. d. The code will compile but an ArithmeticException at runtime. Q49
FlowLayout is the default layout manager for which of the following containers. Select all valid answers? a. Panel b. Applet c. Frame d. Dialog
Q50
Using a FlowLayout Manager, which of the following is the correct way to add a component reference by the variable \a. add(c) b. c.add()
c. add(\d. set(c) Q51
Given the following code snippet
1. class A {
2. public void method(int a, float b) { 3. // some declaration and etc. 4. } 5. }
6. public class B extends A { 7. //Comment here ? 8. }
In class B what all methods can be placed in (// Comment here ?) individually ? a. void method(int i, float a) b. public void method(int i, float f) c public void method()
d. protected int method(float f, int b)
Q52
What does the following program do when it is run with the following command?
java Mystery Mighty Mouse
1. class Mystery {
2. public static void main(String args[]) { 3. Changer c = new Changer(); 4. c.method(args);
5. System.out.println(args[0] + \6. }
7. static class Changer { 8. void method(String s[]) { 9. String temp = s[0]; 10. s[0] = s[1]; 11. s[1] = temp; 12. }
13. } 14. }
a. The program causes and ArrayIndexOutOfBoundsException to be thrown. b. The program runs but does not write anything to the standard output. c. The program writes \d. The program writes \
Q53
What happens when you try to compile and run the following program? 1. class Mystery { 2. String s;
3. public static void main(String args[]) { 4. Mystery m = new Mystery(); 5. m.go(); 6. }
7. void Mystery() { 8. s = \9. }
10. void go() {
11. System.out.println(s); 12. } 13. }
a. The code compiles and throws an exception at run time. b. The code runs, but nothing appears in the standard output. c. The code runs, and \d. The code runs and writes \ Q54
What can you write at the comment //A in the following code so that this program writes the word \1. class RunTest implements Runnable { 2. public static void main(String args[]) { 3. RunTest rt = new RunTest(); 4. Thread t = new Thread(rt);
5. //A 6. }
7. public void run() {
8. System.out.println(\9. }
10. void go() { 11. start(1); 12. }
13. void start(int i) { 14. } 15. }
Select all valid answers.
a. System.out.println(\b. t.start(); c. rt.start(); d. rt.start(1);
Q55
What is wrong with the following code? 1. final class First { 2. private int a = 1; 3. int b = 2; 4. }
5. class Second extends First { 6. public void method() { 7. System.out.println(a+b); 8. } 9. }
a. You cannot invoke println() without passing it a string.
b. Because a is private, no classes other than First can access it. c. Second cannot extend First.
d. final is not a valid keyword for a class. Q56
What is displayed when the following piece of code is executed.
1. class Test extends Thread { 2. public void run() { 3. System.out.print(\4. yield();
5. System.out.print(\6. suspend();
7. System.out.print(\8. resume();
9. System.out.print(\10. }
11 public static void main(String []args) { 12. Test t = new Test(); 13. t.start(); 14. } 15. }
a. Nothing, this is not a valid way to create and start a thread. b. 1 2 c. 1 2 3 d. 1 Q57
What must be true for the RunHandler class so that the instances of RunHandler can be used as written in the following code? 1. class Test {
2. public static void main(String args[]) { 3. Thread t = new Thread(new RunHandler()); 4. t.start(); 5. } 6. }
Select all valid answers ?
a. RunHandler must only implement the java.lang.Runnable interface. b. RunHandler must only extend the Thread class.
c. RunHandler must extend the Thread class or implement Runnable interface. d. RunHandler must provide a run() method declared as public and returning void.
Q58
Which interface implementations can you add as listeners for a TextField object? Select all