Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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

Java, Programming

  • Category:- Java
  • Reference No.:- M91797018
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in Java

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Object-oriented software development1 introduction 11

OBJECT-ORIENTED SOFTWARE DEVELOPMENT 1. Introduction 1.1 Assignment Requirement 1.2 Deliverables and Structure (what to submit) 1.3 Software Restrictions 1.4 How to score high... 1.5 Assumptions 2. System Requirements 2. ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

Assessment instructionsin this assessment you will complete

Assessment Instructions In this assessment, you will complete the programming of two Java class methods in a console application that registers students for courses in a term of study. The application is written using th ...

Simple order processing systemquestion given the classes

Simple Order Processing System Question: Given the classes Ship (with getter and setter), Speedboat, and SpeedboatTest. Answer the following questions: Refine the whole application (all classes) and create Abstract class ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Assessment instructionsin this assessment you will design

Assessment Instructions In this assessment, you will design and code a simple Java application that defines a class, instantiate the class into a number of objects, and prints out the attributes of these objects in a spe ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As