valid answers. a. ActionListener b. FocusListener c. MouseMotionListener d. ContainerListener Q59
Which statements accurately describe the following line of code?
String s[][] = new String[10][]; Select all valid answers. a. This line of code is illegal.
b. s is a two dimensional array containing 10 rows and 10 columns. c. s is an array of 10 arrays. d. Each element in s is set to \Q60
To force a layout manager to re-layout the components in a container, you can invoke the container method called a. validate() b. repaint() c. layout() d. update(); Q61
You need a container to hold six equal-sized button in the three columns of two. This arrangement must persist when the container is resized. Which of the following will create the that container?
a. Canvas c = new Canvas(new GridLayout(2,3)); b. Panel p = new Panel(new GridLayout(2,3)); c. Window w = new Window(new GridLayout(2,3)); d. Panel p = new Panel(new GridLayout(3,2)); Q62
The following lists the complete contents of the file named Derived.java
1. public class Base extends Object { 2. String objType;
3. public Base() { objType = \4. }
5. public class Derived extends Base {
6. public Dervied() { objType = \8. public static void main(String args[]) { 9. Dervied d = new Derived(); 10. } 11. }
What will happen when this file is compiled?
a. Two class files,Base.class and Dervied.class, will be created. b. The compiler will object to line 1. d. The compiler will object to line 2. c. The compiler will object to line 5.
Q63
Your mouseDragged() event handler and your paint method look like this 1. public void mouseDragged(MouseEvent e) { 2. mouseX = e.getX(); 3. mouseY = e.getY(); 4. repaint(); 5. }
6. public void paint(Graphics g) { 7. g.setColor(Color.cyan);
8. g.drawLine(mouseX,mouseY,mouseX+10,mouseY+10); 9. }
You want to modify your code so that the cyan lines accumulate on the screen, rather than getting erased every time repaint() calls update(). What is the simplest way to proceed? a. On line 4, replace repaint() with paint(). b. On line 4, replace repaint() with update(). c. After line 7, add this super.update(g);
d. Add public void update(Graphics g) { paint(g); }
Q64
Given the following code for the Demo class 1. public class Demo {
2. private String [] userNames;
3. public Demo() {
4. userNames = new String[10]; 5. }
6. public void showName(int n) {
7. System.out.println(\8. } 9.
10. public String getName(int n) { 11. return(userNames[n]); 12. } 13. }
What would be the result of calling the showName method with a parameter of 2 immediately after creating an instance of Demo
a. Standard output would show \
b. A NullPointerException would be thrown, halting the program.
c. An ArrayIndexOutOfBoundsException would be thrown halting the program. d. Standard output would show \
Q65
What will be the result of attempting to compile and run the following class? 1. public class Integers {
2. public static void main(String args[]) { 3. System.out.printl(0x10 + 10 + 010); 4. } 5. }
Select the one right answer.
a. The code won't compile. The compiler will complain about the expression 0x10 + 10 + 010 b. When run, the program will print \c. When run, the program will print \d. When run, the program will print \
Q66
How will the following program lay out its buttons? 1. import java.awt.*;
2. public class MyClass {
3. public static void main(String args[]) { 4. String labels[] = {\5. Window grid = new Frame();
6. grid.setLayout(new GridLayout(0,1,2,3));
7. for(int i=0;i 8. grid.add(new Button(labels[i])); 9. }
10. grid.pack();
11. grid.setVisible(true); 12. }
Select the one right answer
a. The program will not show any buttons at all. b. It will place all buttons in one row - A B C D E F.
c. It will place all buttons in one column, i.e., each button in a separate row - A B C D E and F.
d. It will place pairs of buttons in three separate row A B, C D and E F.
Q67
What happens when this method is called with an input of \
1. public String addOK(String S) { 2. S += \3. return S; 4. }
Select one correct answer a. The method will return \b. A runtime exception will be thrown. c. The method will return \d. The method will return \
Q68
What happens during execution of the following program? 1. public class OperandOrder {
2. public static void main(String args[]) { 3. int i=0;
4. int a[] = {3,6}; 5. a[i] = i = 9;
6. System.out.println(i + \7. } 8. }
Select one correct answer.
a. Raises \b. Prints \c. Prints \d. Prints \Q69
Which statements about the output of the following program are true?
1. public class Logic {
2. public static void main(String args[]) { 3. int i = 0; 4. int j = 0; 5. boolean t = true; 6. boolean r;
7. r = (t & 0<(i += 1)); 8. r = (t && 0<(i += 2)); 9. r = (t | 0<(j += 1)); 10. r = (t || 0<(j += 2));
11. System.out.println(i + \12. } 13. }
Select all the valid answers. a. The first digit printed is 1. b. The first digit printed is 3. c. The second digit printed is 3. d. The second digit printed is 1.
Q70
What kind of stream is the System.out object? a. java.io.BufferedWriter b. java.io.PrintStream