Question
Answered

Question 21Which one of the following is used in Java programming to handle asynchronous events?Select one:

a. constructors

b. event handlers

c. overloading

d. pragmatics

e. protocols


Question 22

Consider the following Java program.

1 public class HelloWorld {

2   // My first program!

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

4     System.out.println("Hello, World!");

5   }

6 }

What starts on line 1?


Select one:

a. a statement

b. a package

c. a method definition

d. a comment

e. a class definition


Question 23

Which of the following keywords is useful for skipping to the next iteration of a loop?


Select one:

a. break

b. case

c. continue

d. extends

e. switch


Question 24

What is the output of the following Java program?



interface Food {

  public void printFlavor();

}

class Pepper implements Food {

  public void printFlavor() { System.out.println("spicy"); }

}

public class Lunch {

  public static void main(String[] args) {

    Food pepper = new Pepper();

    pepper.printFlavor();

  }

}


Select one:

a. bland

b. bland

spicy

c. (no output)

d. spicy

e. the program does not compile

bland


Question 25

A subclass will ___ from its superclasses.


Select one:

a. extend

b. implement

c. inherit

d. overload

e. override


Question 26

Consider the following Java program. Which line implements an interface method?



import java.awt.event.*;

import javax.swing.*;

public class MouseWhisperer extends JFrame implements MouseListener {

  MouseWhisperer() {

    super("COME CLOSER");

    setSize(300,100);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    addMouseListener(this);

    setVisible(true);

  }

  public void mouseClicked(MouseEvent e) { setTitle("OUCH"); }

  public void mousePressed(MouseEvent e) { setTitle("LET GO"); }

  public void mouseReleased(MouseEvent e) { setTitle("WHEW"); }

  public void mouseEntered(MouseEvent e) { setTitle("I SEE YOU"); }

  public void mouseExited(MouseEvent e) { setTitle("COME CLOSER"); }

  public static void main(String[] args) { new MouseWhisperer(); }

}



Select one:

a. addMouseListener(this);

b. public class MouseWhisperer extends JFrame implements MouseListener {

c. public static void main(String[] args) { new MouseWhisperer(); }

d. public void mouseEntered(MouseEvent e) { setTitle("I SEE YOU"); }

e. setVisible(true);


Question 27

Which one of the following does NOT describe an array?


Select one:

a. Its elements can be a primitive type.

b. The number of its elements can change.

c. It can be used in a for-each loop.

d. It has a numbered sequence of elements.

e. It provides efficient random access to its elements.


Question 28

Consider the following Java program.

1 public class HelloWorld {

2   // My first program!

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

4     System.out.println("Hello, World!");

5   }

6 }

What starts on line 3?


Select one:

a. a statement

b. a package

c. a method definition

d. a comment

e. a class definition


Question 29

What is the output of the following Java program?



public class Food {

  static int count;

  private String flavor = "sweet";

  Food(String s) { flavor = s; }

  void setFlavor(String s) { flavor = s; }

  String getFlavor() { return flavor; }

  static public void main(String[] args) {

    Food pepper = new Food("spicy");

    System.out.println(pepper.getFlavor());

  }

}


Select one:

a. false

b. smoky

c. spicy

d. sweet

e. true


Question 30

Which of the following can a class NOT be used for?


Select one:

a. a primitive type

b. a container for static methods

c. a container for static variables

d. a type for method parameters

e. a type for variables

Answer & Explanation
Verified Solved by verified expert
Rated Helpful
<p>llentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar</p> Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet

Unlock full access to Course Hero

Explore over 16 million step-by-step answers from our library

Subscribe to view answer

sum dolor s

ec

ng elit. Nam lacinia pulvinar tortor nec facilisis. Pelle

sum dolor sit

ip

Donec aliquet. Lorem

m ipsum dolor sit ame


molestie co

congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, c

itur laoree


itur laoree

, consectetur adipiscing elit. Nam lacinia pulvin



ec aliquet. Lore

, dictum vitae odio. Donec aliquet

o

, dictum vitae odio. Donec ali

usce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec a

o

llentesque dapibus e

onec aliquet. Lorem ipsum dolor sit amet, consec

m risus ante, dapibus a molestie consequat,

nec facilisis. Pellentesque dapibus

sum dolor

o

pulvin



congue ve

gue vel laoreet ac, dictum vitae odio. Do

dictum vit



a molestie

ec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a



facilisis. Pellentesque

, consectetur adipisc

at, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dict

ce dui lectus, congue vel

nec facilisis. Pellentesque dapibus

facilisis. Pellentesque dapibus

ur laoreet. Nam risus ante, dapibus a molestie consequat, ultri

or nec facilisis. Pellentesque dapibus

rem ipsum dolor sit amet, consect

sum dolor

or nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus

ec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante,

ipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesq

m risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui

consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. P

sus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lec

o

ctum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur



ipiscing el

a. Fusce dui lectus, congue vel laoreet ac, dictum vi

ac, dictum vitae odio. Donec aliquet. Lo



fficitur la

ec facilisis. Pellentesque dapibus e

, ultrices ac magna. Fusce

, dictum vitae odio. Donec alique

molestie consequat, ultrices ac magna. Fusce dui lec

ng elit. Nam lacinia pulvinar tortor nec facilisis. Pelle

sum dolor sit

ip

fficitur laoreet. Nam

fficitur laoreet. Nam



Fusce dui

, consectetur adipiscing elit. Nam lacinia pulvin



e vel laoreet ac, d

gue vel laoreet ac, dictu

nec facilisis. Pellentesque dapibus ef

icitur laoreet. Nam risus ante, dapibu

trices ac magna. Fusce dui lectus, congue vel la

, dictum vitae odio. Donec aliquet. Lorem ip

ctum vitae odio. Donec aliquet. Lorem ipsum dolo

inia pulvinar tortor nec facilisis. Pellentesque

usce dui lectus, congue vel laoreet ac, dictum vitae od

sum dolor

o

, ultric



usce dui le

ipiscing elit. Nam lacinia pulvinar tortor nec faci


sus ante, d

Fusce dui lectus,

iscing elit. Nam lacinia pulvinar

s ante, dapibus a molestie consequa

acinia pulvinar tortor nec fac

ur laoreet. Nam risus a

Student reviews
78% (9 ratings)