Wednesday, June 3, 2009

Inheritance

1. An advantage of inheritance is that:
A) all methods can be inherited
B) all instance variables can be uniformly accessed by base classes and derived classes
C) Objects of a derived class can be treated like objects of their base class
D) None of the above.

Points Earned: 1.0/1.0
Correct Answer(s): C




2. A derived class cannot access the ____ members of its base class.
A) private
B) static
C) protected
D) None of the above.

Points Earned: 1.0/1.0
Correct Answer(s): A




3. Which of the following pairs demonstrates the "is-a" relationship?
A) car, engine
B) book, table of contents
C) baseball, sport
D) None of the above

Points Earned: 1.0/1.0
Correct Answer(s): C




4. Which of the following is not a base/derived class relationship?
A) University/Boston University
B) Ford/Taurus
C) Sailboat/Tugboat
D) Country/USA

Points Earned: 1.0/1.0
Correct Answer(s): C




5. Which of the following statements is not true?
A) The class following the ":"in a class declaration is the direct base class of the class being declared.
B) A base class object is a derived class object.
C) C# does not support multiple inheritance.
D) A derived class is generally larger than its base class.

Points Earned: 1.0/1.0
Correct Answer(s): B




6. Identify which of the following examples could be considered a base class for the Computer class?
A) keyboard
B) hard-drive
C) machine
D) software

Points Earned: 1.0/1.0
Correct Answer(s): C




7. Which of the following pairs demonstrates the "has-a" relationship?
A) car, vehicle
B) house, window
C) teacher, person
D) None of the above

Points Earned: 1.0/1.0
Correct Answer(s): B




8. A method must be declared __________ for it to be overridden by derived classes.
A) overrides
B) overridable
C) virtual
D) None of the above

Points Earned: 1.0/1.0
Correct Answer(s): C




9. A class inherited from two or more levels up in the hierarchy is known as a ____.
A) indirect base class
B) direct base class
C) superclass
D) None of the above

Points Earned: 1.0/1.0
Correct Answer(s): A




10. Base class methods with this level of access cannot be called from derived classes.
A) protected
B) package
C) public
D) private

Points Earned: 1.0/1.0
Correct Answer(s): D




11. Inheritance is represented by a(n) ________ relationship.
A) "uses"
B) "is-a"
C) "has-a"
D) None of the above.

Points Earned: 1.0/1.0
Correct Answer(s): B




12. Which of the following classes is the root of the class hierarchy?
A) System.object
B) Point
C) ToString
D) None of the above

Points Earned: 1.0/1.0
Correct Answer(s): A




13. Which of the following is a potential problem associated with using protected instance variables with inheritance?
A) naming collisions occur more frequently
B) a derived-class method may assign illegal values
C) multiple copies of data may become inconsistent
D) None of the above

Points Earned: 1.0/1.0
Correct Answer(s): B




14. When a derived-class member overrides a base-class member, the base-class member can be accessed from the derived-class by using the keyword _____.
A) base
B) top
C) super
D) None of the above

Points Earned: 1.0/1.0
Correct Answer(s): A




15. private fields of a base class can be accessed in a derived class
A) by calling private methods declared in the base class
B) by calling public or protected methods declared in the base class
C) directly
D) All of the above

Points Earned: 1.0/1.0
Correct Answer(s): B




16. To avoid duplicating code (and possibly errors), use ________, rather than ________.
A) inheritance, the "copy-and-paste" approach.
B) the "copy-and-past" approach, inheritance.
C) a class that does not extend object, a class that explicitly extends object.
D) a class that explicitly extends object, a class that does not extend object.

Points Earned: 1.0/1.0
Correct Answer(s): A




17. How can a derived class call a base class constructor?
A) implicitly
B) explicitly
C) A and B
D) the derived class cannot call the base class constructor

Points Earned: 1.0/1.0
Correct Answer(s): C




18. Overriding a method differs from overloading a method because:
A) Overridden methods have the same signature.
B) For an overloaded constructor, the base class constructor will always be called first.
C) Overloaded methods have the same signature.
D) For an overridden constructor, the base class constructor will always be called first.

Points Earned: 1.0/1.0
Correct Answer(s): A




19. Which base class members are inherited by all derived classes of that base class?
A) protected instance variables and methods
B) private constructors
C) private instance variables and methods
D) protected constructors

Points Earned: 1.0/1.0
Correct Answer(s): A




20.
Which of the following statements are true?


A. We can use inheritance to customize existing software.
B. A base class specifies commonality.
C. A base class can be modified without modifying derived classes
D. A derived class can be modified without modifying its derived class.


A) All of the above
B) None of the above
C) A, B and C
D) A, B and D

Points Earned: 1.0/1.0
Correct Answer(s): A




21. The default implementation of method ToString of object returns a string representing ________.
A) the object's type
B) the object class name
C) namespace_name.object_class_name
D) None of the above

Points Earned: 1.0/1.0
Correct Answer(s): C




22. When a derived class constructor calls its base class constructor, what happens if the base class's constructor does not assign a value to an instance variable?
A) a compile-time error occurs
B) a run-time error occurs
C) a syntax error occurs
D) the program compiles and runs correctly because the instance variables are initialized to their default values

Points Earned: 1.0/1.0
Correct Answer(s): D




23. The default Equals implementation determines:
A) whether two references refer to the same object in memory.
B) whether two objects have the same instance variable values.
C) whether two objects have the same instance variables.
D) whether two references have the same type.

Points Earned: 1.0/1.0
Correct Answer(s): A




24. Every class in C#, except __________, extends an existing class.
A) String
B) Integer
C) Class
D) object

Points Earned: 1.0/1.0
Correct Answer(s): D




25. Which statement is true when a base class uses protected instance variables?
A) A derived class object can assign an invalid value to the base class's instance variables, thus leaving the object in an inconsistent state.
B) Derived class methods are more likely to be written so that they depend on the base class's data implementation.
C) We may need to modify all the derived classes of the base class if the base class implementation changes.
D) All of the above.

Points Earned: 1.0/1.0
Correct Answer(s): D




26.
Consider the classes below, declared in the same file:



class A
{
int a;
public A()
{
a = 7;
}
}

class B : A
{
int b;
public B()
{
b = 8;
}
}

Which of the statements below is not true?



A) After the constructor for class B is executed, the variable a will have the value 7.
B) A reference to class A can be treated as a reference to class B.
C) Both variables a and b are instance variables.
D) After the constructor for class B is executed, the variable b will have the value 8.

Points Earned: 1.0/1.0
Correct Answer(s): B




27. Which of the following is an example of a functionality that should not be "factored out" to a base class?
A) All animals lay eggs, except for mammals.
B) All vehicles know how to start and stop.
C) Both ducks and geese are birds that know how to start flying from the water.
D) All paints have a color.

Points Earned: 1.0/1.0
Correct Answer(s): A




28. A problem with inheritance is that a derived class can inherit members it does not need or should not have.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




29. All classes in C# have object as either a direct or indirect base class.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




30. A base class's constructors are inherited into its derived classes.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




31. A class that inherits from another class is referred to as the derived class.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




32. Members of a base class that are private are not inherited by derived classes.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




33. A derived class cannot change the implementation of its base class's methods.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




34. The process of abstraction allows programmers to focus on the commonalities among objects in the system.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




35. Derived classes provide the functionality and features inherited by base classes.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




36. Constructors are never inherited.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




37. A base class may have only one derived class.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




38. The protected members of a class may be accessed in their base class or any classes derived from that base class.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




39. A derived class can effect state changes in base class private members only through public, protected, internal methods provided in the base class and inherited into the derived class.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




40. An object of one class cannot be an object of another class.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




41. Every object of a base class is an object of that class's derived classes.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




42. Multiple inheritance, widely used in C#, is the process of inheriting from more than one class.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




43. Inheritance is the process of building a class with object references of other classes.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




44. A derived class is often larger and more general than its base class.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




45. The first task of any derived-class constructor is to call its base-class constructor.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




46. To enhance performance and reduce errors, it is a good idea to make derived classes larger than they need to be.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




47. Method Equals will accurately compare any two objects.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




48. The base reference may be "chained" to traverse further up in the class hierarchy.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




49. Using protected instance variables can cause derived-class methods to be written to depend on base-class implementation.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




50. When creating derived classes, programmers must use discretion in choosing the proper base class. Ideally, the base class will not contain superfluous capabilities or information.
A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




51. A "copy-and-paste" approach is a simple and efficient way of providing functionality that exists in other classes.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




52. A key to improving the software development process is encouraging software reuse.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




53. When a program creates a derived-class object, the object constructor is the last constructor called and the first whose body finishes executing.
A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




54. Inheritance preserves the integrity of a base class.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




55. If a base class constructor is overridden, the original constructor can no longer be called explicitly by the derived class.
A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




56. Software that requires many modifications due to changing the name of one variable is considered fragile or brittle.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




57. A base class is designed by factoring out similarities among a set of classes.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




58. When a base class method is overridden in a derived class, it is common to have the derived class version call the base class version and do some additional work.
A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




59. Every object in C# has at least seven methods: Equals, Finalize, GetHashCode, GetType, MemberwiseClone, ReferenceEquals, and ToString.
A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




60. There is no modifier that will allow both derived class members and assembly members access.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False

No comments:

Post a Comment