View the step-by-step solution to:

Show the output of running the class Test in the following code lines.


1. Show the output of running the class Test in the following code lines.

interface A {

}


class C {

}


class B extends D implements A {

}


public class Test extends Thread {

public static void main(String[ ] args) {

B b = new B();

if (b instanceof A)

System.out.println("b is an instance of A");

if (b instanceof C)

System.out.println("b is an instance of C");

}

}


class D extends C {

A. b is an instance of A followed by b is an instance of C.

B. b is an instance of A.

C. b is an instance of C.

D. Nothing


2. Analyze the following code.
number[ ] numberArray = new Integer[2];
numberArray[0] = new Double(1.5); (Points : 3)


A. You cannot use Number as a data type because it is an abstract class.

B. Because each element of numberArray is of the Number type, you cannot assign a Double object to it.

C. At runtime, new Integer[2] is assigned to numberArray. This makes each element of numberArrayan Integer object. So you cannot assign a Double object to it.


D. Because each element of numberArray is of the Number type, you cannot assign an Integer object to it.


3. Which of the following statements convert a double value d into a string s? 

A. s = (Double.valueOf(s)).toString();

B. s = (new Double(d)).toString();

C. s = new Double(d).stringOf();

D. s = String.stringOf(d);


4. Assume Calendar calendar = new GregorianCalendar(). _____ returns the month of the year. 

A. calendar.get(Calendar.MONTH)

B. calendar.get(Calendar.WEEK_OF_MONTH)

C. calendar.get(Calendar.MONTH_OF_YEAR)

D. calendar.get(Calendar.WEEK_OF_YEAR)


5. What is the value of evt.getKeyCode() or evt.getChar() for the keyTyped() events? (Points : 3)

A. VK_UNDEFINED

B. The Unicode code of the character

C. The ASCII code of the character

D. A character


6. The getKeyCode() method of the KeyEvent returns _____ (Points : 3)

A. a character.

B. the Unicode code of the character.

C. the ASCII code of the character.

D. None of them


7. The component that processes the listener is called _____ (Points : 3)

A. the adapter object.

B. the listener object.

C. the adaptee object.

D. the source object.


8. To be a listener for ActionEvent, an object must be an instance of _____ (Points : 3)
WindowEvent.

A. EventObject.

B. WindowListener.

C. ActionEvent.

D. ActionListener.


9. Analyze the following code.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test extends JFrame {
public void Test() {
JButton jbtOK = new JButton("OK");
add(jbtOK);
jbtOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("The OK button is clicked");
}
});
}
public static void main(String[ ] args) {
JFrame frame = new Test();
frame.setSize(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}

A. The actionPerformed method is not executed when you click the OK button, because no instance of Test is registered with jbtOK.

B. When you run the program, the button is not displayed, because the constructor is declared wrong. It should be declared public Test(), not public void Test().

C. The message, "The OK button is clicked," is displayed when you click the OK button.

D. The program has a compile error because no listeners are registered with jbtOK.

E. The program has a runtime error because no listeners are registered with jbtOK.

Top Answer

The way to answer this question is ... View the full answer

computer.docx

1. Show the output of running the class Test in the following code lines.
interface A {
} class C {
} class B extends D implements A {
} public class Test extends Thread {
public static void...

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask a homework question - tutors are online