Question 1. 1. (TCO 2) Which of the following is a valid declaration to overload the following function? int whatever (double x); (Points : 6) |
double whatever (double x); int whatever (int x); int whatever2 (double x); int overload (double x); |
Question 2. 2. (TCO 2) The word const inside the parentheses of the following declaration of isEqual bool isEqual (const Distance & rightSideObject) const; (Points : 6) |
ensures the member variables of the called objects are protected (cannot be changed) ensures the argument passed in to the function is protected (cannot be changed) ensures the return value of the function is protected (cannot be changed) ensures the return value is routed to the proper variable |
Question 3. 3. (TCO 2) How many parameters are required to overload the pre-increment operator for a class as a member function? (Points : 6) |
none 1 2 no limit |
Question 4. 4. (TCO 2) Which of the following is called automatically each time an object is created? (Points : 6) |
Compiler Builder Constructor Destructor |
Question 5. 5. (TCO 2) Given the following class definition and lines of code, Line 1 in main is a call to what? class Distance { private: int feet; double inches; public: Distance( ); Distance(int initFt, double initIn); void setFeet(int feetIn); void setInches(double inchesIn); int getFeet() const; double getInches( ) const; }; int main( ) { Distance d1; //Line 1 const int MAX = 100; //Line 2 Distance list[MAX]; //Line 3 Distance d2(1, 2.3); //Line 4 Distance * pDist; //Line 5 d1.feet = 5; //Line 6 // etc. – assume the remaining code is correct } (Points : 6) |
The 0-argument Distance constructor The 2-argument, int, double, Distance constructor The 2-argument, double, int, Distance constructor The 1-argument, int, Distance constructor |
Question 6. 6. (TCO 2) What is the data type of pDist for the code snippet below? Distance * pDIST; (Points : 6) |
Distance Const pointer to Distance Pointer to Distance None of the above |
Question 7. 7. (TCO 2) Given the definition of some class called Employee, which of the following correctly dynamically allocates an array of 20 Employee objects? (Points : 6) |
Employee * myData = new Employee[20]; Employee myData[20] = new Employee[20]; Employee = myData[20]; Employee array = new Employee[20]; |
Question 8. 8. (TCO 2) What is the output of the following code snippet? int value = 10; int * iptr = &value; *iptr = 5; Cout << *iptr << “ “ << value; (Points : 6) |
5 5 10 10 5 10 10 5 |
Question 9. 9. (TCO 2) Which of the following Java statements creates an object of a ButtonHandler class (which implements the ItemListener interface) and associates it with a JRadioButton object called buttonOne? (Points : 6) |
buttonOne.addItemListener(ButtonHandler( )); buttonOne.addItemListener(new ButtonHandler()); buttonOne.+= new ButtonHandler( ); buttonOne.addEventHandlerr(new ButtonHandler( )); |
Question 10. 10. (TCO 2) Which of the following creates a class that properly handles ActionEvents? (Points : 6) |
class handler implements ActionListener {public void actionPerformed(ActionEvent e){//code for event handler} } class handler extends ActionListener {public void handleEvent(ActionEvent e){//code for event handler} } class handler implements ActionListener {public void ActionListener(ButtonEvent e){//code for event handler} } class handler implements ActionListener {public void actionPerformed(ActionListener e){//code for event handler} } |
Question 11. 11. (TCO 2) The x, y drawing coordinate system used in Java graphics (Points : 6) |
uses character units. has the origin in the upper left corner of the display area. uses the x coordinate for the vertical axis. All of the above |
Question 12. 12. (TCO 2) In order to guarantee that only one JRadioButton is selected at any time: (Points : 6) |
add each JRadioButton object to a different panel create a ButtonGroup object and add the JRadioBttons to it have a JCheckBox object manage the three JRadioButtons This cannot be done in Java. |
Question 13. 13. (TCO 2) What can you say about the following Java class? Public class MyApp extends JFrame ( …) (Points : 6) |
MyApp is a Java application. MyApp implements the JFrame interface. MyApp inherits from the JFrame class. MyApp has a nested inner class called JFrame. |
Question 14. 14. (TCO 2) What is the result of the following code? JFrame frame = new JFrame( ); frame.add(new JButton(“One”), BorderLayout.NORTH); frame.add(new JButton(“Two”), BorderLayout.NORTH); frame.setVisible(true); (Points : 6) |
Two buttons are added side by side at the top of the display. Button One was added first, so it is the only button at the top of the display. Button Two was added last, so it is the only button at the top of the display. The Java compiler will not allow you to add two buttons to the same area. |
|