Exam 10: Polymorphism
Exam 1: Introduction65 Questions
Exam 2: Data and Expressions77 Questions
Exam 3: Using Classes and Objects58 Questions
Exam 4: Writing Classes56 Questions
Exam 5: Conditionals and Loops37 Questions
Exam 6: More Conditionals and Loops36 Questions
Exam 7: Object-Oriented Design76 Questions
Exam 8: Arrays70 Questions
Exam 9: Inheritance71 Questions
Exam 10: Polymorphism70 Questions
Exam 11: Exceptions68 Questions
Exam 12: Recursion68 Questions
Exam 13: Collections68 Questions
Select questions type
A JSlider, xSlider, is used to change an icon displayed in the JLabel jlab. xSlider generates a value between 0 and 9, which is then used to index into String[ ] filename, where filename[i] is the ith image available. So xSlider allows the user to select which image appears. Write the stateChange method for a ChangeListener that would be used to implement the ability to change the image based on the JSlider setting.
(Essay)
4.8/5
(35)
To swap the 3ʳᵈ and 4ᵗʰ elements in the int array values, you would do:
values[3] = values[4];
values[4] = values[3];
(True/False)
4.8/5
(42)
Considering the event processing classes, what is the advantage of extending an adaptor class compared to implementing an interface?
(Multiple Choice)
4.8/5
(35)
What are the main programming mechanisms that constitute object-oriented programming?
(Multiple Choice)
4.9/5
(47)
Write a set of code that will create 4 JButtons and add each of these to a JPanel so that they appear in a 2x2 grid. The JButtons will not have any text appear in them (i.e. no commands or names) but instead, will each appear as a color set by the user by using JColorChooser.
(Essay)
4.8/5
(38)
Write the code needed to set up the GUI as a JFrame that includes the JComboBox, the JSlider, the JButton and a JLabel used to output the total cost. The JLabel should initially display "Compute Movie Cost." Use the names jcb, js, jb and jl for the JComboBox, JSlider, JButton and JLabel respectively.
(Essay)
4.9/5
(33)
Write a set of code that will allow a user to select a file through a JFileChooser, read each item of the file, outputting each item to the screen, and close the file at the end.
(Essay)
4.8/5
(44)
What is printed by this code?
Public class Inherit
{
Class Figure
{
Void display( )
{
System.out.println("Figure");
}
}
Class Rectangle extends Figure
{
Void display( )
{
System.out.println("Rectangle");
}
Void display(String s)
{
System.out.println(s);
}
}
Class Box extends Figure
{
Void display( )
{
System.out.println("Box");
}
Void display(String s)
{
System.out.println("This is printed: " + s);
}
}
Inherit( )
{
Figure f = new Figure( );
Rectangle r = new Rectangle( );
Box b = new Box( );
f.display( );
f = r;
f.display("one");
f = b;
f.display("two");
}
Public static void main(String[ ] args)
{
New Inherit( );
}
}
(Multiple Choice)
4.9/5
(42)
An int array stores the following values. Use the array to answer these next questions.
-Which of the following lists of numbers would accurately show the array after the first pass through the Selection Sort algorithm?

(Multiple Choice)
4.8/5
(37)
An int array stores the following values. Use the array to answer these next questions.
-Which of the following lists of numbers would accurately show the array after the second pass of the Selection Sort algorithm?

(Multiple Choice)
4.8/5
(34)
An interface reference can refer to any object of any class that implements the interface.
(True/False)
4.8/5
(40)
What is printed?
Public class Inherit
{
Abstract class Figure
{
Void display( )
{
System.out.println("Figure");
}
}
Class Line extends Figure
{
Void display( )
{
System.out.println("Line");
}
}
Void tryme(Figure f)
{
f.display( );
}
Inherit( )
{
Figure f = new Line( );
Tryme(f);
}
Public static void main(String[ ] args)
{
New Inherit( );
}
}
(Multiple Choice)
4.9/5
(38)
Java allows one to create polymorphic references using inheritance and using interfaces.
(True/False)
4.9/5
(40)
Write an insertion sort method to sort an array of String values (instead of an array of int values). Assume the array is an instance data of the current class called list, and number is an int instance data that stores the number of elements currently stored in list.
(Essay)
5.0/5
(37)
Which of the following classes would you use to open a GUI dialog box, which is then used to select a file to open?
(Multiple Choice)
4.7/5
(46)
Both the Insertion Sort and the Selection Sort algorithms have efficiencies on the order of ________ where n is the number of values in the array being sorted.
(Multiple Choice)
4.7/5
(31)
A reference variable can refer to any object created from any class related to it by inheritance.
(True/False)
4.9/5
(38)
Can a program exhibit polymorphism if it only implements early binding?
(Multiple Choice)
4.9/5
(43)
Showing 41 - 60 of 70
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)