Which statement is true about a non-static inner class

Assignment Help JAVA Programming
Reference no: EM131072658

Part 1

1. Which of the following is a correct interface?

abstract interface A { abstract void print({ };}

interface A { void print() { }; }

abstract interface A { print(); }

interface A { void print();}

2. Analyze the following code.

import java.util.*;                                 // 1

public class Test {                                 // 2

  public static void main(String[ ] args) {     // 3

    Calendar[ ] calendars = new Calendar[10];   // 4

    calendars[0] = new Calendar();                // 5

    calendars[1] = new GregorianCalendar();     // 6

  }                                                     // 7

}                                                       // 8

The program has a compile error on Line 4 because java.util.Calendar is an abstract class.

The program has no compile errors.

The program has a compile error on Line 6 because Calendar[1] is not of a GregorianCalendar type.

The program has a compile error on Line 5 because java.util.Calendar is an abstract class.

3. What is the output of Integer.parseInt("10", 2)?

Invalid statement;

2;

1;

10;

4. Analyze the following code.

Number numberRef = new Integer(0);

Double doubleRef = (Double)numberRef;

The compiler detects that numberRef is not an instance of Double.

The program runs fine, since Integer is a subclass of Double.

A runtime class casting exception occurs, since numberRef is not an instance of Double.

You can convert an int to double, so you can cast an Integer instance to a Double instance.

There is no such class named Integer. You should use the class Int.

5. To divide BigDecimal b1 by b2, and assign the result to b1, you write _____.

b1 = b1.divide(b2);.

b1 = b2.divide(b1);.

b1 = b2.divide(b1);.

b1.divide(b2);.

b2.divide(b1);.

6. 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);

  }

}

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

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().

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

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

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

7. To listen to mouse-clicked events, the listener must implement the _____ interface or extend the _____ adapter.

MouseMotionListener/MouseMotionAdapter

WindowListener/WindowAdapter

ComponentListener/ComponentAdapter

MouseListener/MouseAdapter

8. Clicking the closing button on the upper-right corner of a frame generates a(n) _____ event.

ContainerEvent

WindowEvent

MouseMotionEvent

ItemEvent

ComponentEvent

9. Which statement is true about a non-static inner class?

It must implement an interface.

It must be final if it is declared in a method scope.

It is accessible from any other class.

It can access private instance variables in the enclosing object.

It can only be instantiated in the enclosing class.

10. The method in the ActionEvent _____ returns the action command of the button.

getActionCommand()

getModifiers()

getID()

paramString()

Part 2

1. Which of the following statements are false?

If you compile an interface without errors, but with warnings, a .class file is created for the interface.

If you compile an interface without errors, a .class file is created for the interface.

If you compile a class with errors, a .class file is created for the class.

If you compile a class without errors but with warnings, a .class file is created.

2. To divide BigDecimal b1 by b2, and assign the result to b1, you write _____.

b1 = b1.divide(b2);.

b1 = b2.divide(b1);.

b1 = b2.divide(b1);.

b1.divide(b2);.

b2.divide(b1);.

3. In JDK 1.5, you may directly assign a primitive data type value to a wrapper object. This is called _____.

auto boxing.

auto unboxing.

auto casting.

auto conversion.

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

calendar.get(Calendar.MONTH)

calendar.get(Calendar.WEEK_OF_MONTH)

calendar.get(Calendar.MONTH_OF_YEAR)

calendar.get(Calendar.WEEK_OF_YEAR)

5. What is the output of the following code?

public class Test {

  public static void main(String[ ] args) {

    java.math.BigInteger x = new java.math.BigInteger("3");

    java.math.BigInteger y = new java.math.BigInteger("7");

    x.add(y);

    System.out.println(x);

  }

}

3

11

10

4

6. The interface _____ should be implemented to listen for a button action event.

FocusListener

ContainerListener

ActionListener

MouseListener

WindowListener

7. Which of the following is not a correct name for listener adapters?

MouseAdapter

ActionAdapter

KeyAdapter

WindowAdapter

8. Analyze the following code.

import java.awt.*;                                                         // 1

import java.awt.event.*;                                                  // 2

import javax.swing.*;                                                      // 3

                                                                               // 4

public class Test extends JFrame {                                       // 5

public Test() {                                                       // 6

JButton jbtOK = new JButton("OK");                          // 7

JButton jbtCancel = new JButton("Cancel");                 // 8

getContentPane().add(jbtOK);                                 // 9

getContentPane().add(jbtCancel);                            // 10

jbtOK.addActionListener(this);                              // 11

jbtCancel.addActionListener(this);                         // 12

}                                                                       // 13

                                                                        // 14

public void actionperformed(ActionEvent e) {                    // 15

System.out.println("A button is clicked");                // 16

}                                                                       // 17

                                                                        // 18

public static void main(String[ ] args) {                       // 19

JFrame frame = new Test();                                   // 20

frame.setSize(300, 300);                                      // 21

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   // 22

frame.setVisible(true);                                       // 23

}                                                                       // 24

}                                                                             // 25 (Points : 3)

The program has runtime errors on Lines 9 and 10 because jbtOK and jbtCancel are added to the same location in the container.

The program has compile errors on Line 15 because the signature of actionperformed is wrong.

The program has compile errors on Line 20 because new Test() is assigned to frame (a variable of JFrame).

The program has compile errors on Lines 11 and 12 because Test does not implement ActionListener.

9. Pressing a button generates a(n) _____ event.

ContainerEvent

MouseMotionEvent

ItemEvent

ActionEvent

MouseEvent

10. The method in the ActionEvent _____ returns the action command of the button.

getActionCommand()

getModifiers()

getID()

paramString().

Reference no: EM131072658

Questions Cloud

Considering an investment : Helen is considering an investment of $3,500 each year for 18 years, starting at the end of the this year. The investment will pay 5 % interest. How much will this investment ($) be worth at the end of the 12 years?
What is the equivalent annual savings : Gluon Inc. is considering the purchase of a new high pressure glueball. It can purchase the glueball for $160,000 and sell its old low-pressure glueball, which is fully depreciated, for $28,000. What is the equivalent annual savings from the purchase..
A day in the life of yolanda valdez : Yolanda Valdez, senior vice president for marketing of ClearVision Optical Group, arrived at her office at 7:25 a.m. Settling in at her desk, she began to think about the problems she needed to handle in the course of the day. ClearVision Optical ..
What is an agency relationship : Suppose you decide as did Steve Job and Mark Zuckerberg to start a company. Your product is a software platform that integrates a wide range of media devices, including laptop computers, desktop computers, digital video recorders and cell phones. wha..
Which statement is true about a non-static inner class : Which statement is true about a non-static inner class? Clicking the closing button on the upper-right corner of a frame generates a(n) _____ event.
Write a discussion that reflects your understanding : Write a discussion that reflects your understanding of the readings -"HANDBOOK OF ETHNOGRAPHY by Paul Atkinson, Amanda Coffey, Sara Delamont, John Lofland and Lyn Lofland". It should be no 350-450 words.
Calculate the cash-flow break even quantity : Consider the following production-oriented project. The units produced will sell for $28/unit and can be produced at a variable cost of $20/unit. Fixed costs are $80,000. The purchase price for the project is $200,000, depreciable down to zero over a..
Calculate the operating cash flows of the project : Laurel’s Lawn Care, Ltd., has a new mower line that can generate revenues of $129,000 per year. Direct production costs are $43,000, and the fixed costs of maintaining the lawn mower factory are $16,500 a year. The factory originally cost $0.86 milli..
What is the cash outflow at time : Pierre Imports is evaluating the proposed acquisition of new equipment at a cost of $90,000. In addition the equipment would require modifications at a cost of $10,000 plus shipping costs of $2,000. What is the cash outflow at Time 0?

Reviews

Write a Review

JAVA Programming Questions & Answers

  What is a nested inner class

What is a nested inner class? What special privileges does a nested inner class have? Give an example of how you declare a nested inner class

  Write a program that reads in a text file and then computes

Write a program that reads in a text file and then computes and prints a table of letter frequencies. For example, if the file is the text of "A Tale of Two Cities", found in the file at data/tales.txt , the program will print

  Print the name and number

Question is to print the name and number you entered in order either asked by name or number.

  Prepare an overloaded constructor

Prepare an overloaded constructor that provides values for each field. Also provide get methods for each field. Save the file as Patient.java.

  Write a program to test your class definition

Do not define an input method. The only method that can set the counter is the one that sets it to zero. Write a program to test your class definition.

  Create a sales tracking java program named salestracking

You must create a sales tracking program named SalesTracking.java. This program will use arrays to store and process monthly sales as well as compute average yearly sales, total sales for the year.

  Design and implement a java program that will gather info

Design and implement a Java program that will gather a user's first name, middle initial, lastname, age in years, and 3 lucky numbers. The program should output the following based on the user's input

  Write a test program that obtains from the user

Write a test program that obtains from the user the items to store in two sets A and B, and displays the union A u B, the inter- section A n B, and the dierence A \ B. The data type of the items is your choice. ( you can only store objects.)

  Create at least two vectors and demonstrate the use of each

Create a separate class, VectorTest, that will demonstrate the use of your Vector class. You must create at least two vectors, and demonstrate the use of each method. When you demonstrate the use of each method, print the results to the console ..

  Implement avl trees that allows both iterative traversal

implement avl trees that allows both iterative traversal and recursive traversal.iterative traversal is fairly easy if

  Determine the precise big-oh values

Determine the precise Big-Oh values for each of the following code samples, based on the number of statement executions - Remember to consider each statement in compound statements separately.

  Explain the concept of files and streams

Every seven-letter phone number corresponds to many different seven-letter words. Unforte. nately, most of these words represent unrecognizable juxtapositions of letters.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd