Java Exam 10,12,14

¡Supera tus tareas y exámenes ahora con Quizwiz!

BOTH implement an interface and extend another class

An anonymous inner class must: implement an interface extend another class either implement an interface or extend another class both implement an interface and extend another class

JApplet

An applet using a Swing GUI extends which class? JFrame Applet JApplet JSwing

A horizontal line will be displayed

What does the HTML tag <hr/> cause to happen? A header routine is created. The window will be blanked out before the remainder of the text is displayed. A default header reference will be linked to. A horizontal line will be displayed.

(60, 140)

int[] xCoords = {20,20,60,100,140,140,100,60}; int[] yCoords = {20,100,140,140,100,60,20,20}; What will be the coordinates of the third point of the polygon? (140, 100) (100, 140) (60, 140) (140, 60)

Yellow

super.paint(g); g.setColor(Color.YELLOW); g.fillPolygon(xCoords, yCoords, 8); g.setColor(Color.Black); g.setFont(new Font("SansSerif", Font.Bold,35)); What is the color of the polygon? White Yellow Black None of these

panel.setLayout(new (GridLayout(2,3));

If panel references a JPanel object, which of the following statements adds the GridLayout to it? panel.attachLayout(GridLayout(2,3)); panel.addLayout(new (GridLayout(2,3)); panel.GridLayout(2,3); panel.setLayout(new (GridLayout(2,3));

frame

In GUI terminology, a container that can be displayed as a window is known as a: frame buffer Swing package message dialog

heavyweight

AWT components are commonly called ________ components because they are coupled with their underlying peer classes. heavyweight middleweight lightweight featherweight

are final and static

All fields declared in an interface: have protected access are final and static have private access must be initialized in the class implementing the interface

.html

An HTML document is usually saved with what file name extension? .asp .xml .js .html

applications

In the link produced by the following HTML, what word would you click to go to the linked location? Click here to learn more about <a href="http://www.applications.com"> applications. </a> here Click here to learn more about Click applications

Java Foundation Classes

JFC stands for Java Fundamental Core Java Frame Class Java Fundamental Classes Java Foundation Classes

class hierarchy

Like a family tree, a ________ shows the inheritance relationship between classes. binary tree flowchart class map class hierarchy

It will call the constructor of ClassA that receives an integer as an argument.

Look at the following code and determine what the call to super will do. public class ClassB extends ClassA { public ClassB() { super(10) } } The method super will have to be defined before we can say what will happen. It will call the constructor of ClassA that receives an integer as an argument. It will call the method named super and pass the value 10 to it as an argument. This cannot be determined form the code shown.

8

super.paint(g); g.setColor(Color.YELLOW); g.fillPolygon(xCoords, yCoords, 8); g.setColor(Color.Black); g.setFont(new Font("SansSerif", Font.Bold,35)); How many vertices does the polygon have? 8 5 6 7

1, public class TestApplet extends Applet {

In the following code, which line has an error? public class TestApplet extends Applet { public void init() { JLabel label = new JLabel("Test label"); setLayout(new FlowLayout()); add(label); } } 5 1 3 There are no errors

5, super.JApplet();

In the following code, which line has an error? public class TestApplet extends JApplet { public void init() { super.JApplet(); JLabel label = new JLabel("Test label"); setLayout(new FlowLayout()); add(label); } } 5 1 3 There are no errors

ClassC

In the following statement, which is the interface? public class ClassA extends ClassB implements ClassC ClassA ClassB ClassC Cannot tell

ClassA

In the following statement, which is the subclass? public class ClassA extends ClassB implements ClassC ClassA ClassB ClassC Cannot tell

ClassB

In the following statement, which is the superclass? public class ClassA extends ClassB implements ClassC ClassA ClassB ClassC Cannot tell

The mouse moved

A mouse motion listener class can respond to: The mouse button is released The mouse cursor exits a component's screen space The mouse button is clicked on The mouse moved

All of these

A protected member of a class may be directly accessed by: methods of the same class methods of a subclass methods in the same package All of these

only PUBLIC and PROTECTED members of the superclass

A subclass can directly access: only public and private members of the superclass all members of the superclass only public and protected members of the superclass only protected and private members of the superclass

prefixing its name with the super key word and a dot(.)

A subclass may call an overridden superclass method by: -calling the superclass method first and then calling the subclass method -prefixing its name with the super key word and a dot (.) -using the extends keyword before the method is called -prefixing its name with the name of the superclass in parentheses

necessary to prevent malicious code from attacking or spying on unsuspecting users

Applet restrictions are: necessary to prevent malicious code from attacking or spying on unsuspecting users determined by the Web browser enabled only if the applet is running on a Web server optional in Java 7

extend the capabilities of a web page

Applets are important because the can be used to: convert machine language into HTML run other programs on the user's system extend the capabilities of a web page process large data files

radio.doClick();

Assume that radio references a JRadioButton object. To click the radio button in code, use the following statement: Click(radio); radio.doClick(); radio.Click(); Click(radio, true);

if (checkBox.isSelected()} {/*code to execute, if selected*/}

Assume that the variable checkbox references a JCheckBox object. To determine whether the check box has been selected, use the following code: if (isSelected(checkBox)) {/*code to execute, if selected*/} if (checkBox.isSelected()) {/*code to execute, if selected*/} if (checkBox) {/*code to execute, if selected*/} if (checkBox.doClick()) {/*code to execute, if selected*/}

AWT

Because these components rely on the appearance and behavior of the underlying operating system components, there is little that can be done by the programmer to change their properties. Container Swing AWT JFC

All of these

Due to security restrictions, applets cannot: Delete files Read the contents of files Create files on the user's system All of these

implement an interface

Event listeners must: not receive any arguments implement an interface exit the application once it has handled the event be included in private inner classes

ClassB must override each method in ClassA

Given the following code which of the following is TRUE? public class ClassB implements ClassA{} -ClassB must override each method in ClassA. -ClassA inherits from ClassB. -ClassB inherits from ClassA. -ClassA must override each method in ClassB.

1

Given the following code, how many times per second will the TimerListener event be generated? Timer timer = new Timer(1000, new TimerListener()); 100 1 1000 10

the more general classes are toward the top of the tree and the more specialized are toward the bottom

In a class hierarchy: the more general classes are toward the left of the tree and the more specialized are toward the right the more general classes are toward the bottom of the tree and the more specialized are toward the top the more general classes are toward the top of the tree and the more specialized are toward the bottom the more general classes are toward the right of the tree and the more specialized are toward the left

All of these

In an HTML document, the tags: instruct the Web browser how to format the text instruct the Web browser where to place images instruct the Web browser what to do when the user clicks on a link All of these

BorderLayout

This layout manager arranges components in five regions. GridLayout RegionLayout FlowLayout BorderLayout

BorderLayout

This layout manager arranges components in regions named North, South, East, West, and Center. RegionLayout FlowLayout BorderLayout GridLayout

FlowLayout

This layout manager arranges components in rows. FlowLayout BorderLayout RegionLayout GridLayout

JFrame.EXIT_ON_CLOSE

To end an application, pass this as the argument to the JFrame class's setDefaultCloseOperation() method. JFrame.CLOSE_NOT_HIDE END_ON_CLOSE JFrame.EXIT_ON_CLOSE JFrame.END_ON_CLOSE

import javax.swing; import java.awt;

To include Swing and AWT components in your program, use the following import statements: import java.swing; import javax.awt; import javax.swing; import java.awt; import java.swing; import java.awt; import javax.swing; import javax.awt;

None of these

Look at the following code. The method in line ________ will override the method in line ________. Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public int method1(int a){} Line 5 public double method2(int b){} Line 6 } Line 7 public ClassB extends ClassA Line 8 { Line 9 public ClassB(){} Line 10 public int method1(int b, int c){} Line 11 public double method2(double c){} Line 12 } 10, 4 11, 5 Both 10, 4 and 11, 5 None of these

It does not override methodA

Look at the following code. What is missing from ClassA? Line 1 public interface MyInterface Line 2 { Line 3 int FIELDA = 55; Line 4 public int methodA(double); Line 5 } Line 6 public class ClassA implements MyInterface Line 7 { Line 8 FIELDA = 60; Line 9 public int methodB(double) { } Line 10 } It does not override methoda. It does not have a constructor. It does not overload methoda. Nothing is missing. It is a complete class

4

Look at the following code. Which line has an error? Line 1 public interface Interface1 Line 2 { Line 3 int FIELDA = 55; Line 4 public int methodA(double){} Line 5 } 1 2 3 4

pixel

One of the small dots that make up a screen display is known as what? texture color point pixel

appletviewer TestApplet.html

One way of viewing the results of the applet which is invoked in the HTML document TestApplet.html is to enter the following at the command prompt. appletviewer TestApplet.html viewapplet TestApplet.html view TestApplet appleviewer TestApplet

Circle

1. import javax.swing.*; 2. import java.awt.*; 3. public class GraphicsTest extends JApplet{ 4. public void init() 5. { 6. Container contentPane getContentPane(); 7. contentPane.setBackground(Color.white); 8. } 9. public void paint(Graphics g) 10. { 11. super.paint(g); 12. g.setColor(Color.yellow); 13. g.fillOval(100, 100, 50, 50); 14. g.setColor(color.black); 15. g.setFont(new Font("SansSerif", Font.BOLD, 35)); 16. g.drawString("SLOW", 110, 110); 17. } 18. } What shape will the oval have? Oblong, width greater than height Oblong, width less than height Circle Cannot tell

(125,125)

1. import javax.swing.*; 2. import java.awt.*; 3. public class GraphicsTest extends JApplet{ 4. public void init() 5. { 6. Container contentPane getContentPane(); 7. contentPane.setBackground(Color.white); 8. } 9. public void paint(Graphics g) 10. { 11. super.paint(g); 12. g.setColor(Color.yellow); 13. g.fillOval(100, 100, 50, 50); 14. g.setColor(color.black); 15. g.setFont(new Font("SansSerif", Font.BOLD, 35)); 16. g.drawString("SLOW", 110, 110); 17. } 18. } What will be the coordinates of the center oval? (100, 100) (50, 50) (125, 125) (100, 50)

14, g.setColor(Color.Black);

1. import javax.swing.*; 2. import java.awt.*; 3. public class GraphicsTest extends JApplet{ 4. public void init() 5. { 6. Container contentPane getContentPane(); 7. contentPane.setBackground(Color.white); 8. } 9. public void paint(Graphics g) 10. { 11. super.paint(g); 12. g.setColor(Color.yellow); 13. g.fillOval(100, 100, 50, 50); 14. g.setColor(color.black); 15. g.setFont(new Font("SansSerif", Font.BOLD, 35)); 16. g.drawString("SLOW", 110, 110); 17. } 18. } Which line sets the color that will be used to draw "SLOW"? 16 7 12 14

2

How many radio buttons can be selected at the same time as the result of the following code? hours = new JRadioButton("Hours"); minutes = new JRadioButton("Minutes"); seconds = new JRadioButton("Seconds"); days = new JRadioButton("Days"); months = new JRadioButton("Months"); years = new JRadioButton("Years"); timeOfDayButtonGroup = new ButtonGroup(); dateButtonGroup = new ButtonGroup(); timeOfDayButtonGroup.add(hours); timeOfDayButtonGroup.add(minutes); timeOfDayButtonGroup.add(seconds); dateButtonGroup.add(days); dateButtonGroup.add(months); dateButtonGroup.add(years); 1 2 3 4

a link to another Web page

Hypertext can contain: a link to another Web page executable code a Java application program exception methods

an exception is thrown

If an applet attempts to violate one of the JVM restrictions: it will display a window stating that it has violated the restriction. the program has a fatal error. an exception is thrown. it automatically notifies the Web server of the violation.

button1.setBackground(Color.BLUE);

If button1 is a JButton object, which of the following statements will make its background blue? button1.setBackground(Color.BLUE); button1.makeBackground(Color.BLUE); button1.set.Background(BLUE); button1.makeBackground(BLUE);

public members in classB are public in ClassA, but private members in ClassB cannot be directly accessed in ClassA

If ClassA extends ClassB, then: public members in ClassB are public in ClassA, but private members in ClassB cannot be directly accessed in ClassA public and private members of ClassB are public and private, respectively, in ClassA neither public or private members in ClassB can be directly accessed in ClassA private members in ClassB are changed to protected members in ClassA

a chain of inheritance

If ClassC extends ClassB, which extends ClassA, this would be an example of: a family tree packaging multiple inheritance a chain of inheritance

All of these

If a class contains an abstract method: -you cannot create an instance of the class -the method will have only a header, but not a body, and end with a semicolon -the method must be overridden in subclasses -All of these

the method will have only a header, but NOT a body, and END with a semicolon ;

If a class contains an abstract method: you must create an instance of the class the method will have only a header, but not a body, and end with a semicolon the method cannot be overridden in subclasses All of these.

With a line that has an OPEN arrowhead at one end that points to the SUPERCLASS

In UML diagrams, inheritance is shown: With a line that has a closed arrowhead at one end that points to the superclass With a line that has an open arrowhead at one end that points to the superclass With a line that has a closed arrowhead at one end that points to the subclass With a line that has an open arrowhead at one end that points to the subclass

event driven

Programs that operate in a GUI environment must be: event driven dialog boxes in color layout managers

You can next panels inside the cells, and add other components to the panels

The GridLayout manager limits each cell to only one component. To put two or more components in a cell, do this: The statement is false. The GridLayout manager does not have this restriction You can nest panels inside the cells, and add other components to the panels Resize the components to fit in the cell Resize the cells so they can hold more

Graphics

The ________ object is responsible for drawing the entire applet window. Applet Graphics JFrame SuperClass

decorations

The minimize button, maximize button, and close button on a window are sometimes referred to as: display buttons decorations sizing buttons operations buttons

add each button to a panel one at a time, e.g. panel.add(button1);

The variable panel references a JPanel object. The variable bGroup references a ButtonGroup object, which contains several button components. If you want to add the buttons to the panel: use the statement, Panel panel = new Panel(bGroup); use the statement, bGroup.add(panel); use the statement, panel.add(bGroup); add each button to panel one at a time, e.g. panel.add(button1);

Swing

These components have a consistent look and predictable behavior on any operating system. Swing AWT Peer classes GUI

Frame

This is a basic window that has a border around it, a title bar, and a set of buttons for minimizing, maximizing, and closing the window. Frame Dialog box Pane Container

Splash Screen

This is a graphic image that is displayed while an application loads into memory and starts up. Blue screen of death The Java 8 trademark screen Splash screen Memory usage screen

event

This is an action that takes place in an application, such as the clicking of a button. event instance case effect

panel

This is commonly used to hold and organize collections of related components: frame panel list label

import java.awt.event.*;

To use the ActionListener interface, as well as other event listener interfaces, you must have the following import statement in your code: import java.awt.*; import java.awt.event.*; import java.swing; import java.awt;

import java.awt.*;

To use the Color class, which is used to set the foreground and background of various objects, use the following import statement: import java.swing; import java.awt.event.*; import java.awt.*; import java.awt;

Creates an AddButtonListener object and registers the AddButtonListener object with the addButton

What does the following statement do? addButton.addActionListener(new AddButtonListener()); Creates an AddButtonListener object Registers the addButton object as an ActionListener with the AddButtonListener object Creates an AddButtonListener object and registers the AddButtonListener object with the addButton Nothing, the statement is invalid.

A paragraph break

What does the tag <p /> cause to happen? Plain text to be displayed A double space A paragraph break Indentation for a paragraph

The text inside the tag will be centered just the same.

What will happen if you use </center> instead of </CENTER> in an HTML document? The text inside the tag will be centered just the same. The tag will be ignored. The text inside the tag will be centered and appear in all uppercase letters. An exception will be thrown.

2

Given the following code, how many times per second will the TimerListener event be generated? Timer timer = new Timer(500, new TimerListener()); 5 50 500 2

(0,299)

If a frame component is 200 pixels wide and 300 pixels high, the lower, left-hand corner has (X, Y) coordinates of: (0, 300) (0, 0) (200, 0) (0, 299)

(299,0)

If a frame component is 300 pixels wide and 200 pixels high, the upper, right-hand corner has (X, Y) coordinates of: (300, 0) (299, 0) (0, 0) (200, 300)

Java will automatically call the superclass's default or no-arg constructor JUST BEFORE the code in the subclass's constructor executes

If a subclass constructor does not explicitly call a superclass constructor: Java will automatically call the superclass's default or no-arg constructor IMMEDIATELY AFTER the code in the subclass's constructor executes it must include the code necessary to initialize the superclass fields Java will automatically call the superclass's default or no-arg constructor JUST BEFORE the code in the subclass's constructor executes the superclass fields will be set to the default values for their data types

then a class that inherits from it, MUST CALL one of the constructors that the superclass does have

If a superclass does not have a default constructor or a no-arg constructor: then a class that inherits from it, must initialize the superclass values. then a class that inherits from it, must call one of the constructors that the superclass does have. then a class that inherits from it, must contain the default constructor for the superclass. then a class that inherits from it, does not inherit the data member fields from the superclass.

overloaded

If two methods have the same name but different signatures, they are: overloaded subclass methods overridden superclass methods

package

If you do not provide an access specifier for a class member, the class member is given ________ by default. package protected private public

JLabel

In Swing, labels are created with this class: SwingLabel AWTLabel JLabel JFCLabel

JFrame class

In a Swing application, you create a frame object from the: JFrame class Jlabel class AbstractButton class Jpanel class

with event listeners, exactly as they are in GUI applications

In an applet, events are handled: with event listeners, exactly as they are in GUI applications by always terminating the applet with special applet event listeners differently, depending upon which computer is running the applet

The superclass constructor always executes before the subclass constructor

In an inheritance relationship: The subclass constructor always executes before the superclass constructor The superclass constructor always executes before the subclass constructor The unified constructor always executes first regardless of inheritance The constructor with the lowest overhead always executes first regardless of inheritance

public access

In an interface all methods have: public access protected access packaged access private access

A URL object containing the location of the HTML file that invoked the applet

In the following code, what does getDocumentBase()return? play(getDocumentBase(), "mysound.wav"); A URL object containing the location of the applet's .class file The sound file itself The HTML location "mysound.wav" A URL object containing the location of the HTML file that invoked the applet

It will call the constructor of ClassA that receives an integer as an argument.

In the following code, what will the call to super do? public class ClassB extends ClassA { public ClassB() { super(40); System.out.println("This is the last statement " + "in the constructor."); } } This cannot be determined from the code. It will call the constructor of ClassA that receives an integer as an argument. It will call the method super and pass the value 40 to it as an argument. The method super will have to be defined before we can say what will happen.

This is an error and will cause the program to crash

Look at the following code. Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public void method1(int a){} Line 5 } Line 6 public class ClassB extends ClassA Line 7 { Line 8 public ClassB(){} Line 9 public void method1(){} Line 10 } Line 11 public class ClassC extends ClassB Line 12 { Line 13 public ClassC(){} Line 14 public void method1(){} Line 15 } Which method will be executed when the following statements are executed? ClassC item1 = new ClassA(); item1.method1(); Line 4 Line 9 Line 14 This is an error and will cause the program to crash.

10, 4

Look at the following code. The method in line ________ will override the method in line ________. Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public int method1(int a){} Line 5 public double method2(int b){} Line 6 } Line 7 public ClassB extends ClassA Line 8 { Line 9 public ClassB(){} Line 10 public int method1(int b){} Line 11 public double method2(double c){} Line 12 } 4, 10 5, 11 10, 4 11, 5 Both 4, 10 and 5, 11

Line 9

Look at the following code: Look at the following code. Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public void method1(){} Line 5 } Line 6 public class ClassB extends ClassA Line 7 { Line 8 public ClassB(){} Line 9 public void method1(){} Line 10 } Line 11 public class ClassC extends ClassB Line 12 { Line 13 public ClassC(){} Line 14 public void method1(){} Line 15 } Which method1 will be executed when the following statements are executed? ClassA item1 = new ClassB(); item1.method1(); Line 4 Line 9 Line 14 This is an error and will cause the program to crash.


Conjuntos de estudio relacionados

EVR 3013 quiz 4,5 & 6 study guide

View Set

chap 15 real estate taxes and other liens instructor question

View Set

International Business Chapter 7

View Set

Accounting Final Exam Review Questions & Answers

View Set

Manufacturing Processes Chapter 40

View Set