Deck 10: Polymorphism
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/70
العب
ملء الشاشة (f)
Deck 10: Polymorphism
1
Which of the following GUI components would you use to allow the user to select between a range of numeric alternatives?
A) JComboBox
B) JList
C) JSlider
D) JScrollPane
E) JOptionPane
A) JComboBox
B) JList
C) JSlider
D) JScrollPane
E) JOptionPane
C
Explanation: C) The JSlider has a range of numbers and the user slides the slider to the selection that they desire.
Explanation: C) The JSlider has a range of numbers and the user slides the slider to the selection that they desire.
2
What does the following code do? Assume list is an array of int values, temp is some previously initialized int value, and c is an int initialized to 0.
For (j=0; j < list.length; j++)
If (list[j] < temp) c++;
A) It finds the smallest value and stores it in temp
B) It finds the largest value and stores it in temp
C) It counts the number of elements equal to the smallest value in list
D) It counts the number of elements in list that are less than temp
E) It sorts the values in list to be in ascending order
For (j=0; j < list.length; j++)
If (list[j] < temp) c++;
A) It finds the smallest value and stores it in temp
B) It finds the largest value and stores it in temp
C) It counts the number of elements equal to the smallest value in list
D) It counts the number of elements in list that are less than temp
E) It sorts the values in list to be in ascending order
D
Explanation: D) The statement if (list[j] < temp) c++; compares each element in list to temp and adds one to c only if the element is less than temp, so it counts the number of elements in list less than temp, storing this result in c.
Explanation: D) The statement if (list[j] < temp) c++; compares each element in list to temp and adds one to c only if the element is less than temp, so it counts the number of elements in list less than temp, storing this result in c.
3
What is printed by the following code? Consider the polymorphic invocation.
Public class Inherit
{
Class Figure
{
Void display( )
{
System.out.println("Figure");
}
}
Class Rectangle extends Figure
{
Void display( )
{
System.out.println("Rectangle");
}
}
Class Box extends Figure
{
Void display( )
{
System.out.println("Box");
}
}
Inherit( )
{
Figure f = new Figure( );
Rectangle r = new Rectangle( );
Box b = new Box( );
F)display( );
F = r;
F)display( );
F = b;
F)display( );
}
Public static void main(String[ ] args)
{
New Inherit( );
}
}
A) Figure Rectangle
Box
B) Rectangle Box
C) Figure Figure
Figure
D) Syntax error. This code won't compile or execute
E) none of the above
Public class Inherit
{
Class Figure
{
Void display( )
{
System.out.println("Figure");
}
}
Class Rectangle extends Figure
{
Void display( )
{
System.out.println("Rectangle");
}
}
Class Box extends Figure
{
Void display( )
{
System.out.println("Box");
}
}
Inherit( )
{
Figure f = new Figure( );
Rectangle r = new Rectangle( );
Box b = new Box( );
F)display( );
F = r;
F)display( );
F = b;
F)display( );
}
Public static void main(String[ ] args)
{
New Inherit( );
}
}
A) Figure Rectangle
Box
B) Rectangle Box
C) Figure Figure
Figure
D) Syntax error. This code won't compile or execute
E) none of the above
A
Explanation: A) This is a perfect example of polymorphism. The first invocation of the display method has a Figure as its referent. In the second invocation, the reference has been changed to Rectangle. Then for the third invocation it has been changed to Box.
Explanation: A) This is a perfect example of polymorphism. The first invocation of the display method has a Figure as its referent. In the second invocation, the reference has been changed to Rectangle. Then for the third invocation it has been changed to Box.
4
How many passes will it take in all for Selection Sort to sort this array?
A) 2
B) 4
C) 5
D) 6
E) 7
A) 2
B) 4
C) 5
D) 6
E) 7
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
5
Assume that x is a GUI component from the javax.swing library. The instruction x.getValue( ) returns the value selected by the user from component x where x would be of which specific swing class?
A) JComboBox
B) JList
C) JSlider
D) JButton
E) all of the above
A) JComboBox
B) JList
C) JSlider
D) JButton
E) all of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
6
Comparing the performance of selection sort and insertion sort, what can one say?
A) Selection sort is more efficient than insertion sort
B) Insertion sort is more efficient than selection sort
C) The efficiencies of both sorts are about the same
D) The efficiencies of both sorts depend upon the data being sorted
E) none of the above
A) Selection sort is more efficient than insertion sort
B) Insertion sort is more efficient than selection sort
C) The efficiencies of both sorts are about the same
D) The efficiencies of both sorts depend upon the data being sorted
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
7
The showDialog method is part of which class?
A) JOptionPane
B) JColorChooser
C) JTextArea
D) Keyboard
E) all of the above
A) JOptionPane
B) JColorChooser
C) JTextArea
D) Keyboard
E) all of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
8
What are the main programming mechanisms that constitute object-oriented programming?
A) encapsulation, inheritance, polymorphism
B) encapsulation, abstraction, inheritance
C) inheritance, polymorphism, recursion
D) polymorphism, recursion, abstraction
E) none of the above
A) encapsulation, inheritance, polymorphism
B) encapsulation, abstraction, inheritance
C) inheritance, polymorphism, recursion
D) polymorphism, recursion, abstraction
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
9
Which of the following GUI components would you use to display a list of options when the component is first clicked so that the user could select between the entries?
A) JComboBox
B) JList
C) JSlider
D) JScrollPane
E) JOptionPane
A) JComboBox
B) JList
C) JSlider
D) JScrollPane
E) JOptionPane
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
10
Comparing the amount of memory required by selection sort and insertion sort, what can one say?
A) Selection sort requires more additional memory than insertion sort
B) Insertion sort requires more additional memory than selection sort
C) Both methods require about as much additional memory as the data they are sorting
D) Neither method requires additional memory
E) None of the above
A) Selection sort requires more additional memory than insertion sort
B) Insertion sort requires more additional memory than selection sort
C) Both methods require about as much additional memory as the data they are sorting
D) Neither method requires additional memory
E) None of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
11
Which of the following is a listener class for a JSlider?
A) ListListener
B) ActionListener
C) ButtonListener
D) ChangeListener
E) SlideListener
A) ListListener
B) ActionListener
C) ButtonListener
D) ChangeListener
E) SlideListener
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
12
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?
A) 9, 4, 12, 2, 6, 8, 18
B) 2, 4, 9, 6, 12, 8, 18
C) 2, 4, 12, 9, 6, 8, 18
D) 2, 4, 6, 8, 9, 12, 18
E) 2, 4, 12, 6, 8, 9, 18

Which of the following lists of numbers would accurately show the array after the second pass of the Selection Sort algorithm?
A) 9, 4, 12, 2, 6, 8, 18
B) 2, 4, 9, 6, 12, 8, 18
C) 2, 4, 12, 9, 6, 8, 18
D) 2, 4, 6, 8, 9, 12, 18
E) 2, 4, 12, 6, 8, 9, 18
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
13
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.
A) n
B) n * log n
C) n²
D) n³
E) Insertion sort has an efficiency of n and Selection Sort has an efficiency of n²
A) n
B) n * log n
C) n²
D) n³
E) Insertion sort has an efficiency of n and Selection Sort has an efficiency of n²
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
14
We compare sorting algorithms by examining
A) the number of instructions executed by the sorting algorithm
B) the number of instructions in the algorithm itself (its length)
C) the types of loops used in the sorting algorithm
D) the amount of memory space required by the algorithm
E) whether the resulting array is completely sorted or only partially sorted
A) the number of instructions executed by the sorting algorithm
B) the number of instructions in the algorithm itself (its length)
C) the types of loops used in the sorting algorithm
D) the amount of memory space required by the algorithm
E) whether the resulting array is completely sorted or only partially sorted
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
15
Which of the following classes would you use to open a GUI dialog box, which is then used to select a file to open?
A) JOptionPane
B) JTextArea
C) showOpenDialog
D) JFileChooser
E) JFileReader
A) JOptionPane
B) JTextArea
C) showOpenDialog
D) JFileChooser
E) JFileReader
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
16
Polymorphism is achieved by
A) overloading
B) overriding
C) embedding
D) abstraction
E) encapsulation
A) overloading
B) overriding
C) embedding
D) abstraction
E) encapsulation
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
17
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 fourth pass of the Selection Sort algorithm?
A) 9, 4, 12, 2, 6, 8, 18
B) 2, 4, 6, 9, 12, 8, 18
C) 2, 4, 6, 8, 9, 12, 18
D) 2, 4, 6, 9, 8, 12, 18
E) 2, 4, 6, 8, 12, 9, 18

Which of the following lists of numbers would accurately show the array after the fourth pass of the Selection Sort algorithm?
A) 9, 4, 12, 2, 6, 8, 18
B) 2, 4, 6, 9, 12, 8, 18
C) 2, 4, 6, 8, 9, 12, 18
D) 2, 4, 6, 9, 8, 12, 18
E) 2, 4, 6, 8, 12, 9, 18
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
18
Which of the following GUI components would you use to allow the user to move the view of the components within the container?
A) JComboBox
B) JList
C) JSlider
D) JScrollPane
E) JOptionPane
A) JComboBox
B) JList
C) JSlider
D) JScrollPane
E) JOptionPane
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
19
Which of the following GUI components would you use to display a list of options so that the user could select between the entries in the list?
A) JComboBox
B) JList
C) JSlider
D) JScrollPane
E) JOptionPane
A) JComboBox
B) JList
C) JSlider
D) JScrollPane
E) JOptionPane
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
20
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?
A) 9, 4, 12, 2, 6, 8, 18
B) 4, 9, 12, 2, 6, 8, 18
C) 2, 4, 12, 9, 6, 8, 18
D) 2, 4, 6, 8, 9, 12, 18
E) 2, 4, 9, 12, 6, 8, 18

Which of the following lists of numbers would accurately show the array after the first pass through the Selection Sort algorithm?
A) 9, 4, 12, 2, 6, 8, 18
B) 4, 9, 12, 2, 6, 8, 18
C) 2, 4, 12, 9, 6, 8, 18
D) 2, 4, 6, 8, 9, 12, 18
E) 2, 4, 9, 12, 6, 8, 18
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
21
What kind of performance can you expect if you perform linear search on a sorted array?
A) The performance will be about the same as on an unsorted array
B) The performance will be much better than on an unsorted array
C) The performance will be much worse than on an unsorted array
D) The performance will be worse than ⁿ² in this case
E) none of the above
A) The performance will be about the same as on an unsorted array
B) The performance will be much better than on an unsorted array
C) The performance will be much worse than on an unsorted array
D) The performance will be worse than ⁿ² in this case
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
22
Can a program exhibit polymorphism if it only implements early binding?
A) Yes, because one form of polymorphism is overloading
B) No, because without late binding polymorphism cannot be supported
C) Yes, because so long as the programs uses inheritance and/or interfaces it supports polymorphism
D) Yes, because early binding has nothing to do with polymorphism
E) none of the above
A) Yes, because one form of polymorphism is overloading
B) No, because without late binding polymorphism cannot be supported
C) Yes, because so long as the programs uses inheritance and/or interfaces it supports polymorphism
D) Yes, because early binding has nothing to do with polymorphism
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
23
As explained in the Software Failure, the destruction of the Ariane 5 expendable launch system was caused by
A) strong aerodynamic forces
B) a failure of design and testing
C) a malfunction of the rocket's control system
D) over-confidence of the designers after success of the Ariane 4 system
E) all of the above
A) strong aerodynamic forces
B) a failure of design and testing
C) a malfunction of the rocket's control system
D) over-confidence of the designers after success of the Ariane 4 system
E) all of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
24
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( );
}
}
A) Figure Rectangle
B) Figure Rectangle
Figure
Box
C) Figure Figure
Figure
Figure
D) Rectangle Figure
Box
Figure
E) Syntax errorthis code won't even compile
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( );
}
}
A) Figure Rectangle
B) Figure Rectangle
Figure
Box
C) Figure Figure
Figure
Figure
D) Rectangle Figure
Box
Figure
E) Syntax errorthis code won't even compile
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
25
A JSlider provides a list of String choices that the user can select between.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
26
Which of the following statements is completely True?
A) If a class is declared to be abstract then every method in the class is abstract and must be overridden
B) If a class is declared to be abstract then some methods in the class may have their bodies omitted
C) If a class is declared to be abstract then all methods in the class must have their bodies omitted
D) If a class is declared to be abstract then all the instance variables must be overridden when a concrete class is derived from the abstract base class
A) If a class is declared to be abstract then every method in the class is abstract and must be overridden
B) If a class is declared to be abstract then some methods in the class may have their bodies omitted
C) If a class is declared to be abstract then all methods in the class must have their bodies omitted
D) If a class is declared to be abstract then all the instance variables must be overridden when a concrete class is derived from the abstract base class
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
27
To swap the 3ʳᵈ and 4ᵗʰ elements in the int array values, you would do:
values[3] = values[4];
values[4] = values[3];
values[3] = values[4];
values[4] = values[3];
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
28
A polymorphic reference can refer to different types of objects over time.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
29
What is the efficiency of binary search?
A) n²
B) n
C) log₂ n
D) n/2
E) none of the above
A) n²
B) n
C) log₂ n
D) n/2
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
30
Considering the event processing classes, what is the advantage of extending an adaptor class compared to implementing an interface?
A) Adaptors save the programmer from having to create a collection of empty-bodied methods
B) Adaptors save the programmer from having to create inner classes
C) Adaptors can be used even when interfaces cannot
D) Adaptors are more efficient at run time
E) none of the above
A) Adaptors save the programmer from having to create a collection of empty-bodied methods
B) Adaptors save the programmer from having to create inner classes
C) Adaptors can be used even when interfaces cannot
D) Adaptors are more efficient at run time
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
31
It is possible to sort an array of int, float, double or String, but not an array of an Object class such as a CD class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
32
What is printed by the following code?
Public class Inherit
{
Abstract class Speaker
{
Abstract public void speak( );
}
Class Cat extends Speaker
{
Public void speak( )
{
System.out.println("Woof!");
}
}
Class Dog extends Speaker
{
Public void speak( )
{
System.out.println("Meow!");
}
}
Inherit( )
{
Speaker d = new Dog( );
Speaker c = new Cat( );
D)speak( );
C)speak( );
}
Public static void main(String[ ] args)
{
New Inherit( );
}
}
A) Woof! Meow!
B) Meow! Woof!
C) Meow! Meow!
D) Woof! Woof!
E) none of the above
Public class Inherit
{
Abstract class Speaker
{
Abstract public void speak( );
}
Class Cat extends Speaker
{
Public void speak( )
{
System.out.println("Woof!");
}
}
Class Dog extends Speaker
{
Public void speak( )
{
System.out.println("Meow!");
}
}
Inherit( )
{
Speaker d = new Dog( );
Speaker c = new Cat( );
D)speak( );
C)speak( );
}
Public static void main(String[ ] args)
{
New Inherit( );
}
}
A) Woof! Meow!
B) Meow! Woof!
C) Meow! Meow!
D) Woof! Woof!
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
33
Which of these methods will sort an array of floats into ascending order?
A) void arrange(float[ ] ary) {
For (int n=0; nFor (int k=n; kIf (ary[n] > ary[k])
{
Float x = ary[n];
Ary[n] = ary[k];
Ary[k] = x;
}
}
B) void arrange(float[ ] ary) {
For (int n=0; nFor (int k=n; kIf (ary[n] < ary[k])
{
Float x = ary[n];
Ary[n] = ary[k];
Ary[k] = x;
}
}
C) void arrange(float[ ] ary) {
For (int n=1; n<=ary.length; n++)
For (int k=n; kIf (ary[n] > ary[k])
{
Float x = ary[n];
Ary[n] = ary[k];
Ary[k] = x;
}
}
D) void arrange(float[ ] ary) {
For (int n=0; nFor (int k=n; kIf (ary[n] > ary[k])
Float x = ary[n];
Ary[n] = ary[k];
Ary[k] = x;
}
E) none of the above
A) void arrange(float[ ] ary) {
For (int n=0; n
{
Float x = ary[n];
Ary[n] = ary[k];
Ary[k] = x;
}
}
B) void arrange(float[ ] ary) {
For (int n=0; n
{
Float x = ary[n];
Ary[n] = ary[k];
Ary[k] = x;
}
}
C) void arrange(float[ ] ary) {
For (int n=1; n<=ary.length; n++)
For (int k=n; k
{
Float x = ary[n];
Ary[n] = ary[k];
Ary[k] = x;
}
}
D) void arrange(float[ ] ary) {
For (int n=0; n
Float x = ary[n];
Ary[n] = ary[k];
Ary[k] = x;
}
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
34
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( );
}
}
A) Line
B) Figure
C) Shape
D) Syntax error; the code won't even compile
E) none of the above
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( );
}
}
A) Line
B) Figure
C) Shape
D) Syntax error; the code won't even compile
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
35
Although insertion sort and selection sort have generally the same O(n²) performance, selection sort has an advantage of insertion sort. What is this advantage?
A) Selection sort usually makes fewer comparisons
B) Selection sort usually makes fewer swaps
C) Selection sort usually makes fewer passes
D) Selection sort usually makes fewer selections
E) none of the above
A) Selection sort usually makes fewer comparisons
B) Selection sort usually makes fewer swaps
C) Selection sort usually makes fewer passes
D) Selection sort usually makes fewer selections
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
36
Which statement is completely True?
A) Java upcasts automatically, but you must explicitly downcast
B) Java downcasts automatically, but you must explicitly upcast
C) Java expects the user to explicitly upcast and downcast
D) Java will both upcast and downcast automatically
E) The rules for upcasting and downcasting depend upon whether classes are declared public, protected, or private
A) Java upcasts automatically, but you must explicitly downcast
B) Java downcasts automatically, but you must explicitly upcast
C) Java expects the user to explicitly upcast and downcast
D) Java will both upcast and downcast automatically
E) The rules for upcasting and downcasting depend upon whether classes are declared public, protected, or private
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
37
What is printed?
Public class Inherit
{
Abstract class Figure
{
Void display( )
{
System.out.println("Figure");
}
}
Abstract class Rectangle extends Figure
{
}
Class Box extends Rectangle
{
Void display( )
{
System.out.println("Rectangle");
}
}
Inherit( )
{
Figure f = (Figure) new Box( );
F)display( );
Rectangle r = (Rectangle) f;
R)display( );
}
Public static void main(String[ ] args)
{
New Inherit( );
}
}
A) Rectangle Rectangle
B) Rectangle Figure
C) Figure Rectangle
D) Figure Figure
E) none of the above
Public class Inherit
{
Abstract class Figure
{
Void display( )
{
System.out.println("Figure");
}
}
Abstract class Rectangle extends Figure
{
}
Class Box extends Rectangle
{
Void display( )
{
System.out.println("Rectangle");
}
}
Inherit( )
{
Figure f = (Figure) new Box( );
F)display( );
Rectangle r = (Rectangle) f;
R)display( );
}
Public static void main(String[ ] args)
{
New Inherit( );
}
}
A) Rectangle Rectangle
B) Rectangle Figure
C) Figure Rectangle
D) Figure Figure
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
38
What is printed?
public class Inherit
{
class Figure
{
void display( )
{
System.out.println("Figure");
}
}
class Rectangle extends Figure
{
void display( )
{
System.out.println("Rectangle");
}
}
class Box extends Figure
{
void display( )
{
System.out.println("Box");
}
}
Inherit( )
{
Figure f = new Figure( );
Rectangle r = new Rectangle( );
Box b = new Box( );
f.display( );
f = r;
f.display( );
f = b;
f.display( );
}
public static void main(String[ ] args)
{
new Inherit( );
}
}
A) Figure
Rectangle
Box
B) Rectangle
Box
C) Figure
Figure
Figure
D) Syntax error; this code won't compile or execute
E) none of the above
public class Inherit
{
class Figure
{
void display( )
{
System.out.println("Figure");
}
}
class Rectangle extends Figure
{
void display( )
{
System.out.println("Rectangle");
}
}
class Box extends Figure
{
void display( )
{
System.out.println("Box");
}
}
Inherit( )
{
Figure f = new Figure( );
Rectangle r = new Rectangle( );
Box b = new Box( );
f.display( );
f = r;
f.display( );
f = b;
f.display( );
}
public static void main(String[ ] args)
{
new Inherit( );
}
}
A) Figure
Rectangle
Box
B) Rectangle
Box
C) Figure
Figure
Figure
D) Syntax error; this code won't compile or execute
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
39
What is printed?
Public class Inherit
{
Class Figure
{
Void display( )
{
System.out.println("Figure");
}
}
Class Rectangle extends Figure
{
Void display( )
{
System.out.println("Rectangle");
}
}
Class Box extends Rectangle
{
Void display( )
{
System.out.println("Box");
}
}
Inherit( )
{
Figure f = new Figure( );
Rectangle r = new Rectangle( );
Box b = new Box( );
F)display( );
F = r;
((Figure) f).display( );
F = (Figure) b;
F)display( );
}
Public static void main(String[ ] args)
{
New Inherit( );
}
}
A) Figure Rectangle
Box
B) Figure Figure
Figure
C) Figure Rectangle
Figure
D) Rectangle Figure
E) none of the above
Public class Inherit
{
Class Figure
{
Void display( )
{
System.out.println("Figure");
}
}
Class Rectangle extends Figure
{
Void display( )
{
System.out.println("Rectangle");
}
}
Class Box extends Rectangle
{
Void display( )
{
System.out.println("Box");
}
}
Inherit( )
{
Figure f = new Figure( );
Rectangle r = new Rectangle( );
Box b = new Box( );
F)display( );
F = r;
((Figure) f).display( );
F = (Figure) b;
F)display( );
}
Public static void main(String[ ] args)
{
New Inherit( );
}
}
A) Figure Rectangle
Box
B) Figure Figure
Figure
C) Figure Rectangle
Figure
D) Rectangle Figure
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
40
"class Aggregate" is incorrect. Choose the correct line so that this program prints Granite: weight=25.0 value=4 numKind=7
Public class Inherit
{
Abstract class Stone
{
Protected float weight = 13;
Protected int value = 4;
Abstract public String toString( );
}
Class Aggregate
{
Protected int numKind;
}
Class Granite extends Aggregate
{
Granite( )
{
Weight = 25; numKind = 7;
}
Public String toString( )
{
Return "Granite: weight="
+ weight + " value="
+ value + " numKind="
+ numKind;
}
}
Inherit( )
{
Granite g = new Granite( );
System.out.println(g);
}
Public static void main(String[ ] args)
{
New Inherit( );
}
}
A) abstract class Aggregate {
B) abstract class Aggregate extends Granite {
C) abstract class Aggregate extends Stone {
D) class Aggregate extends Stone {
E) none of the above
Public class Inherit
{
Abstract class Stone
{
Protected float weight = 13;
Protected int value = 4;
Abstract public String toString( );
}
Class Aggregate
{
Protected int numKind;
}
Class Granite extends Aggregate
{
Granite( )
{
Weight = 25; numKind = 7;
}
Public String toString( )
{
Return "Granite: weight="
+ weight + " value="
+ value + " numKind="
+ numKind;
}
}
Inherit( )
{
Granite g = new Granite( );
System.out.println(g);
}
Public static void main(String[ ] args)
{
New Inherit( );
}
}
A) abstract class Aggregate {
B) abstract class Aggregate extends Granite {
C) abstract class Aggregate extends Stone {
D) class Aggregate extends Stone {
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
41
Choosers-like file choosers and color choosers-provide a mechanism for a user to make a selection among numerous alternatives, and these mechanisms are provided within the Java packages.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
42
A class reference can refer to any object of any class that descends from the class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
43
Demonstrate how the following array is sorted using Insertion Sort. Show the array after each pass of the outer loop.
[16, 3, 12, 13, 8, 1, 18, 9]
[16, 3, 12, 13, 8, 1, 18, 9]
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
44
Binary search can be used on unsorted datait will just perform more slowly.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
45
A method's parameter can be polymorphic, giving the method flexible control of its arguments.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
46
Demonstrate how the following array is sorted using Selection Sort. Show the array after each pass of the outer loop.
[16, 3, 12, 13, 8, 1, 18, 9]
[16, 3, 12, 13, 8, 1, 18, 9]
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
47
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
48
Regarding the Software Failure: There was a segment in the Ariana 5 software to convert a floating-point number to a signed 16-bit integer, but once the number was converted, it was out of range for 16 bits.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
49
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
50
Write a set of code to define a vertical JSlider that goes from 1 to 1000 with tick marks every 100 and default to be set in the middle (at 500), with a background color of 0, 0, 255.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
51
An interface reference can refer to any object of any class that implements the interface.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
52
One of the advantages of linear search is that it does not require its data to be sorted.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
53
A reference variable can refer to any object created from any class related to it by inheritance.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
54
Explain how to alter the Selection Sort algorithm so that it sorts in descending order instead of ascending order.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
55
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
56
An interface name can be used to declare an object reference variable.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
57
The fact that the System.out.println( ) method is able to handle such a wide variety of objects, and print them correctly, is an example of the polymorphic nature of the println( ) method.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
58
Write a set of code that will allow a user to select a file through a JFileChooser and store all items in the String array list to the selected file, closing the file when done.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
59
The type of the reference, not the type of the object, is use to determine which version of a method is invoked in a polymorphic reference.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
60
Java allows one to create polymorphic references using inheritance and using interfaces.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
61
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
62
Why is it almost always a good idea to implement a toString( ) method when you define a class?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
63
Consider this statement: If you declare a (polymorphic) reference variable, v, to be of type Object, by saying: Object v; then v can refer to any kind of object without restriction. If "object" means an instance of the Object class, is this statement True?
Why or why not?
If "object" means any kind of Java data, is this statement True?
Why or why not?
Why or why not?
If "object" means any kind of Java data, is this statement True?
Why or why not?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
64
The GUI should react whenever the JButton is clicked, so the JFrame will need an ActionListener. Write the actionPerformed method to implement the ActionListener so that the GUI will compute the cost of the movie when the JButton is clicked. This method will have to obtain the values specified in the JComboBox and the JSlider and output the computed cost in the JLabel. Assume that a Matinee costs $5.00 per ticket, a Rush Hour show $3.50 per ticket and Normal show costs $7.50 per ticket.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
65
Consider the code shown below. It contains a syntax error, preventing successful compilation and execution. What is the error?
public class Inherit
{
class Figure
{
void display( )
{
System.out.println("Figure");
}
}
class Rectangle extends Figure
{
final void display( )
{
System.out.println("Rectangle");
}
}
class Box extends Rectangle
{
void display( ) {
System.out.println("Box");
}
}
Inherit( )
{
Figure f = new Figure( );
Rectangle r = new Rectangle( );
Box b = new Box( );
f.display( );
r.display( );
b.display( );
}
public static void main(String[ ] args)
{
new Inherit( );
}
}
public class Inherit
{
class Figure
{
void display( )
{
System.out.println("Figure");
}
}
class Rectangle extends Figure
{
final void display( )
{
System.out.println("Rectangle");
}
}
class Box extends Rectangle
{
void display( ) {
System.out.println("Box");
}
}
Inherit( )
{
Figure f = new Figure( );
Rectangle r = new Rectangle( );
Box b = new Box( );
f.display( );
r.display( );
b.display( );
}
public static void main(String[ ] args)
{
new Inherit( );
}
}
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
66
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
67
Why would you not need to implement a ChangeListener for the JSlider?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
68
What is early binding?
What is late binding?
What is late binding?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
69
Explain why an abstract method cannot be declared private.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
70
Is it possible to use both overloading and overriding in the same method?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck