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. ActionListener
c. JButton
d. JFrame
e. this
Question 2
Question text
Consider the following Java program. What is the superclass of "MouseWhisperer"?
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. java.awt.event
b. JFrame
c. MouseEvent
d. MouseListener
e. this
Question 3
Question text
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(); }
}
Select one:
a. java.awt.event
b. JFrame
c. MouseEvent
d. MouseListener
e. this
Question 4
Question text
A class that implements a listener interface does which of the following?
Select one:
a. It generates events.
b. It handles events.
c. It maintains an object directory.
d. It records audio.
e. It runs an event loop.
Clear my choice
Question 5
Question text
Consider the following Java program. Which one of the following is an interface?
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. java.awt.event
b. JFrame
c. MouseEvent
d. MouseListener
e. this
Inheritence is the object oriented concept in Java Programming.
Two concepts in inheritence is :- Subclass and Superclass.
subclass is the child class that inherits from another class.
superclass is the parent class being inherited from
In Java programming inheritence is implemented by using extends keyword.
Fromat : Class subclass name extends superclass name.
Question 1:
Answer : - Option d . JFrame
Subclass Clicker inherits superclass JFrame using extends keyword.
Question 2:
Answer : - Option b. JFrame
Subclass MouseWhisperer inherits superclass JFrame using extends keyword.
Question 3:
Answer : - Option e. this
Once a class implements MouseListener that class's object can register as a listener for the action events.
So here class MouseWhisperer implements MouseListener and object of MouseWhisperer registers event listener.
Question 4:
Answer : - Option b. It handles events.
A class that implements a listener interface handles the events.
Question 5:
Answer : - Option d. MouseListener
Interface in Java is similar to a class but has some differences compare to class.
While using interfaces in java programming it uses implements keyword to implement the interface.
In the given program code it is given that,
public class MouseWhisperer extends JFrame implements MouseListener
uses implements MouseListener. From the usage of implements keyword we can identify that
" MouseListener " is the interface.
Get Answers For Free
Most questions answered within 1 hours.