Question

1) Consider the following Java program, which one of the following best describes "setFlavor"? public class...

1) Consider the following Java program, which one of the following best describes "setFlavor"?

public class Food {
    static int count;
    private String flavor = "sweet";
    Food() { count++; }
    void setFlavor(String s) { flavor = s; }
    String getFlavor() { return flavor; }
    static public void main(String[] args) {
        Food pepper = new Food();
        System.out.println(pepper.getFlavor());
    }
}

a. a class variable

b. a constructor

c. a local object variable

d. an instance variable

e. a method

2) In a do-while loop, how many times does the continuation condition run (if the loop has no break, return, or System.exit calls)?

a. At least once, at the beginning of each iteration.

b. At least once, at the end of each iteration.

c. Exactly once.

d. Zero or more times, at the beginning of each iteration.

e. Zero or more times, at the end of each iteration.

3) Which one of the following is an event handler?

a. an event generator

b. an event listener

c. an event loop

d. an event method

e. java.awt.event

4) Consider the following Java program. Which one of the following is a package?
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(); }
}

a. java.awt.event

b. JFrame

c. MouseEvent

d. MouseListener

e. this

5) Consider the following Java method. Which term best describes what this method computes?

static int doSomething(int[] a) {
    int b = a[0];
    for (int c : a) if (b > c) b = c;
    return b;
}

a. average

b. maximum

c. minimum

d. sum

e. transpose

6) Consider the following Java program, what starts on line 2?
1 public class HelloWorld {
2     // My first program!
3     public static void main(String[] args) {
4         System.out.println("Hello, World!");
5     }
6 }

a. a variable declaration

b. a statement

c. a method (subroutine) definition

d. a comment

e. a class definition

7) What is the output of the following Java program?
import java.util.*;
class ArrayGames {
    public static void main(String[] args) {
        int[] a = new int[5];
        System.out.println(Arrays.toString(a));
    }
}

a. null

b. [0, 0, 0, 0, 0]

c. [5, 5, 5, 5, 5]

d. [null, null, null, null, null]

e. No output. It throws an exception.

8) Consider the following class definition. Which variables can be used in the missing "println" expression on line 8?
1 public class PrintStuff
2 {
3      public static void main()
4      {
6          {
7              int i = -1;
8              System.out.println(_____);
9          }
10         int j = 1;
11         for (j = 0; j < 10; j++) {
12             System.out.println(_____);
13         }
14         {
15             int k;
16             for (k = 0; k < 10; k++) {
17                System.out.println(_____);
18             }
19         }
20        System.out.println(_____);
21     }
22 }

a. Only "i"

b. Only "j"

c. Only "k"

d. "i" and "j"

e. "j" and "k"

9) Consider the following Java statements.
int x = 3;
x = x++;

What is the value x is holding?

a. 0

b. 3

c. 4

d. 5

e. The question is moot. The statements have a syntax error.

10) Consider the following Java method. Which term best describes what this method computes?

static int doSomething(int[] a) {
    int b = 0;
    for (int c : a) b += c;
    return b;
}

a. average

b. maximum

c. minimum

d. sum

e. transpose

11) Consider the following Java method, which term best describes "'("Hello, World!")"?

public static void main(String[] args) {
    System.out.println("Hello, World!");
}

a. actual parameter or argument

b. formal parameter

c. method call

d. modifier

e. return type

12) Consider the following Java method, which term best describes "void"?
public static void main(String[] args) {
    System.out.println("Hello, World!");
}

a. actual parameter or argument

b. formal parameter

c. method call

d. modifier

e. return type

13) What is the output of the following Java program?
class Sum {
    static int sum = 0;
    static void add(int i) { sum += i; }
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) add(i);
        System.out.println(sum);
    }
}

a. 0

b. 9

c. 10

d. 45

e. 100

14) Consider the following Java program. Which object registers event listeners?
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(); }
}

a. java.awt.event

b. JFrame

c. MouseEvent

d. MouseListener

e. this

15) What is the output of the following Java program?
class Food {
    Food() { printFlavor(); }
    void printFlavor() { System.out.println("bland"); }
}
class Pepper extends Food {
    void printFlavor() { System.out.println("spicy"); }
}
public class Lunch {
    public static void main(String[] args) {
        Food lunch = new Pepper();
    }
}

a. bland

b. bland
spicy

c. no output

d. spicy

e. the program does not compile

Homework Answers

Answer #1

Answer 1: e. a method
setFlavour() is method used to set the data to the
private instance data floavor
Wrong Answers:
A: it is not static variable
B: Construcot name should be same as class name
C: it is not object
D: it is a method not

Answer 2:
a. At least once, at the beginning of each iteration.

Do while will check the condiition post iteration so
it will execute atleast once

Answer 3:
d. an event method
Event methods wil handle the evetnts
like actionPerformed ,mouseClicked


Answer 4:
a. java.awt.event

Wrong Answers:
JFrame is class
MouseEvent is class
MouseListener is interface
this is keyword

As per policy we can answer 1 question per post. Please post the remianing questions as separate post.Thanks

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Consider the following Java program. What is the superclass of "Clicker"? import java.awt.event.*; import javax.swing.*; public...
Consider the following Java program. What is the superclass of "Clicker"? import java.awt.event.*; import javax.swing.*; public class Clicker extends JFrame implements ActionListener {     int count;     JButton button;     Clicker() {         super("Click Me");         button = new JButton(String.valueOf(count));         add(button);         button.addActionListener(this);         setSize(200,100);         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         setVisible(true);     }     public void actionPerformed(ActionEvent e) {         count++;         button.setText(String.valueOf(count));     }     public static void main(String[] args) { new Clicker(); } } Select one: a. ActionEvent b....
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*;...
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*; import javax.swing.*; public class Clicker extends JFrame implements ActionListener {     int count;     JButton button;     Clicker() {         super("Click Me");         button = new JButton(String.valueOf(count));         add(button);         button.addActionListener(this);         setSize(200,100);         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         setVisible(true);     }     public void actionPerformed(ActionEvent e) {         count++;         button.setText(String.valueOf(count));     }     public static void main(String[] args) { new Clicker(); } } a. add(button);...
Consider the following Java program. Describe what it does in response to specific operations of the...
Consider the following Java program. Describe what it does in response to specific operations of the mouse, and how it does it. (You are encouraged to run the program for yourself to test its behavior. Then read through the program carefully to understand how that behavior arises.) 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)...
What is the output of the following Java program? public class Food {     static int...
What is the output of the following Java program? public class Food {     static int count;     private String flavor = "sweet";     Food() { count++; }     void setFlavor(String s) { s = flavor; }     String getFlavor() { return flavor; }     static public void main(String[] args) {         Food pepper = new Food();         pepper.setFlavor("spicy");         System.out.println(pepper.getFlavor());     } } Select one: a. sweet b. 1 c. The program does not compile. d. 2 e. spicy...
Consider the following Java program : public static void main (string args [ ]) { int...
Consider the following Java program : public static void main (string args [ ]) { int result, x ; x = 1 ; result = 0; while (x < = 10) { if (x%2 == 0) result + = x ; + + x ; } System.out.println(result) ; } } Which of the following will be the output of the above program? A. 35 B. 30 C. 45 D. 35 2. public static void main(String args[]) { int i =...
What is the output of the following Java program? interface Food {     public void printFlavor();...
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. spicy b. no output c. the program does not compile d. bland e. bland spicy
What is the output of the following Java program? class Food { Food() { System.out.println(flavor); }...
What is the output of the following Java program? class Food { Food() { System.out.println(flavor); } String flavor = "bland"; } class Pepper extends Food { String flavor = "spicy"; } public class Lunch { public static void main(String[] args) { Food lunch = new Pepper(); } } Select one: a. spicy b. the program does not compile c. bland spicy d. no output e. bland
What is the output of the following Java program? class Food { String flavor = "bland";...
What is the output of the following Java program? class Food { String flavor = "bland"; } class Pepper extends Food { String flavor = "spicy"; Pepper(String flavor) { this.flavor = flavor; } } public class Lunch { public static void main(String[] args) { Pepper pepper = new Pepper("sweet"); System.out.println(pepper.flavor); } } Select one: a. bland b. the program does not compile c. no output d. spicy e. sweet
JAVA -Consider this program: public class Main { public static void main(String[] args) { String s1...
JAVA -Consider this program: public class Main { public static void main(String[] args) { String s1 = new String("hello"); String s2 = "hello"; String s3 = "hello";    System.out.println(s1 == s3); System.out.println(s1.equals(s3)); System.out.println(s2 == s3); } } When we run the program, the output is: false true true Explain why this is the output, using words and/or pictures.
Java question Consider the following: 1 class SnoopDogg { 2 int count; 3 } 4 class...
Java question Consider the following: 1 class SnoopDogg { 2 int count; 3 } 4 class Test { 5 public static void main ( String [] args ) { 6 SnoopDogg myCount = new SnoopDogg (); 7 myCount.count = 0; 8 int times = 0; 9 increment( myCount, times ); 10 System.out.println( myCount.count ); 11 System.out.println( times ); 12 } 13 public static void increment (SnoopDogg sd, int times ) { 14 sd.count = sd.count + 1; 15 times =...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT