1. public class AStringQuestion { 2. static String s1; 3. static String s2;
4. public static void main(String args[]) { 5. s2 = s1+s2;
6. System.out.println(s2); 7. } 8. }
[Select one correct answer] a. Will cause a compilation error.
b. Runtime Execption - NullPointerException in the 2nd line of the main method. c. Will compile successfully and print \d. Will compile successfully and print an empty line on the screen.
Q82
What is the result of attempting to compile and run the following program? 1. import java.io.*;
2. public class OutOut {
3. public static void main(String args[]) throws IOException { 4. PrintStream pr = new PrintStream(new FileOutputStream(\5. System.out = pr;
6. System.out.println(\7. } 8. }
[Select one correct answer]
a. The code causes a compiler error. out is a declared final in System and cannot be assigned to pr.
b. The code causes a runtime Exception due the assignment to a final variable.
c. The code compiles and runs success fully. A file called \see what I see now??\
d. The code cause a compiler error. PrintStream is an abstract class
Q83
What is the result of attempting to compiler and run the following piece of code. 1. import java.awt.*;
2. public class TestFrame extends Frame {
3. public TestFrame() {
4. Button one = new Button(\5. Button two = new Button(\6. Button three = new Button(\7. setLayout(new FlowLayout()); 8. add(one); 9. add(two); 10. add(three);
11. setSize(1000,1000); 12. setVisible(true); 13. two.setVisible(false); 14. }
15. public static void main(String args[]) { 16. TestFrame tf = new TestFrame(); 17. } 18. }
Select one correct answer
a. If the above code runs, the buttons - one and three are laid out in a single row from left to right with a gap in between.
b. If the above code runs, the buttons - one and three are laid out in a single row from left to right with no gap in between.
c. Code does not compile - a component can not be hidden after being added to a container. d. Code gets compiled successfully but throws runtime Exception - a component can not be hidden after being added to a container. Q84
What is the result of attempting to compile and run the following piece of code?
1. import java.awt.*;
2. public class TestFrame extends Frame { 3. public TestFrame() { 4. CheckboxGroup chg = null;
5. Checkbox ch = new Checkbox(\6. setLayout(new FlowLayout()); 7. add(ch); 8. pack();
9. setVisible(true); 10. } 11.
12. public static void main(String args[]) { 13. TestFrame tf = new TestFrame(); 14. } 15. }
[Select one correct answer]
a. It will cause a compilation error as the checkbox group is null in the constructor. b. It will compile successfully but throws a runtime exception because the checkbox group is null in the constructor of the check box.
c. It will compile and run successfully. The checkbox appears as a single radio button which is always true
d. It will compile and run successfully. The checkbox bears its original appearence and does not appear as a radio button.
Q85
What is the result of attempting to compile and run the following program? 1. public class Test { 2. private int i = j; 3. private int j = 10; 4.
5. public static void main(String args[]) { 6. System.out.println((new Test()).i); 7. } 8. }
[Select one correct answer]
a. Compiler error complaining about access restriction of private variables of Test. b. Compiler error complaining about forward referencing. c. No error - The output is 0; d. No error - The output is 10; Q86
What is the result of attempting to compile and run the following program
1. public class A {
2. private void method1() throws Exception {
3. throw new RuntimeException(); 4. }
6. public void method2() { 7. try { 8. method1();
9. } catch(RuntimeException e) {
10. System.out.println(\11. } catch(Exception e) {
12. System.out.println(\13. } 14. }
15. public static void main(String args[]) { 16. A a = new A(); 17. a.method2(); 18. } 19. }
[Select one correct answer] a. It will not compile.
b. It will compile and show - \c. It will compile and show - \
d. It will compile and show both the messages one after another in the order they appear.
Q87
Assume that Cat is a class and String[] args is the argument passed to the public static void main(String args[]) method of the class. The class is executed with the following command line string
c;\\somedirectory> java Cat
An expression in the main method is as follows
1. System.out.println(args.length);
What is the result of attempting to compile and run the snipped. a. The above expression will cause a '0' appear on the command line. b. It will throw a NullPointerException. c. It will cause a nk line to appear.
d. It will cause a comilation error at line 1 due to length.
Q88
Given the following snippet of code 1. char c = -1;
What is the result of compiling the above snippet.
a. It will cause a compiler error as the range of character is between 0 and 2^16 - 1. Will request for an explicit cast.
b. It will not cause a compiler error and c will have the value -1; c. The variable c will not represent any ascii character. d. The variable c will still be a unicode character. Q89
Given the following code fragment.
1. switch( x ) { 2. case 100
3. System.out.println(\4. case 200
5. System.out.println(\6. case 300
7. System.out.println(\8. }
Choose all of the declarations of x that will not cause a compiler error. a. byte x = 100; b. short x = 200; c. int x = 300; d. long x = 400;
Q90
What happens to the file system when the following code is run and the myFile object is created? Assume that name represents a valid path and file name for a file that does not presently exist.
1. File createFile(String name) { 2. File myFile = new File(name); 3. return myFile; 4. }