COMP121-Test 1

Card Set Information

COMP121-Test 1
2012-10-06 12:18:12
computer programming java big comp121 frank university

Flash Cards to prepare for test one of COMP121 from franklin university
Show Answers:

  1. What is an interface type in java?
    A java interface type declares methods but does not provide their implementations.
  2. What are the differences between an interface type and a class?
    • All methods in an interface type are abstract (that is they have a name, parameters, and a return tpe, but they don't have an implementation).
    • All methods in an interface type are automatically public. 
    • An interface type does not have instance variables.
  3. What reserved word is use to indicate that a class implements an interface type?
  4. Can you convert from a class type to an interface type?
    Yes, provided the class implements the interface
  5. What do you need to convert from an interface type to a class type?
    A Cast
  6. What is a mechanism for bundling up a block of code so that it ca be invoked at a later time?
    A Callback
  7. What is an inner class?
    An inner class is declared inside another class. Inner classes are commonly used for utility classes that should not be visible elsewhere in a program.
  8. The more general class in an inheritance hierarchies?
    It's a superclass
  9. The more specialized class that inherits from teh superclass is called the?
  10. True or False: The instance variables declared in the superclass are present in subclass objects?
  11. True or False: A subclass does not inherit the methods of its superclass.
    Flase - they do inherit the methods.
  12. True or False: A subclass has access to private instance variables of its superclass.
    False - the subclass does not have access to private instance variables of its superclass.
  13. In what way does inheritance differ from implementing an interface?
    • An interface is not a class. 
    • An interface has no behavior. 
    • An interface merely tells you which methods you should implement.
    • A superclass has behavior that the subclasses inherit.
  14. A subclass method overrides a superclass method if it has the same________ and _______ as a superclass method.
    • Name
    • Parameter Types
  15. What reserve word is used to all a method of the superclass?
  16. To call the superclass constructor, you use the ____ reserved word in the first state of the subclass constructor.
  17. When the reserved word super is immediately followed by a parenthesis, it indicates a call to ________. When used this way, the constructor call must be the first statement of the subclass constructor. If super is followed by a period and a method name, on the other hand, it indicates a call to ________ (can be made anywehre in any subclass).
    • The superclass constructor.
    • A superclass method.
  18. True or False: Subclass references can be converted to superclass references. 
  19. What can you use to protect against bad casts?
    The instanceof operator - it tests whether an object belongs to aparticular type. 
  20. True or Flase: In Java, the type of a variable does not determine the type of the object to which it refers. 
    True. For example, a variable of type BankAccount can hold a reference to an actual BankAccount object or a subclass object such as SavingsAccount. 
  21. When the virtual machine calls an instance method, it locates the method of the implicit parameter's class. This is called ___ .
    Dynamic Method Lookup. Java uses DML to determine which method to invoke. The method called is always determined by the type of the actual object, not the type of the variable. 
  22. ______ is a method whose implementation is not specified. 
    Abstract Method 
  23. An __________ is a class that cannot be instantiated. 
    Abstract Class. 
  24. True or False: A class that declares an abstract method, or that inherits an abstract method without overriding it, must be declared as abstract. 
    True - You can also declare classes with no abstract methods as abstract. Doing so prevents programmers from creating instances of that class but allows them to create their own subclasses. 
  25. True or False: You can construct an object of an abstract class.
    False - You cannot construct an object of an abstract class. You can still have a variable whose type is an abstract class. Of course, the actual object to which it refers must be an instance of a concrete subclas. 
  26. You can prevent other programmers from creating subclasses or from overriding certain methods. In this situation you would use _____ reserved word. This means that nobody can extend the class.
    Final. The string class is meant to be immutable - string objects can't be modified by any of their methods. Nobody can create subclasses of String; therefore you know that all String references can be copied without the risk of mutation.
  27. Inherited methods ____ be overridden; instance variables ____ be overriden.
    • Can
    • Cannot (Although they can be redefined in teh subclass, but that's not the same thing, and there's almost never a need to do it). 
  28. Why is inheritence beneficial?
    • You avoid duplicate code
    • you guarantee that all classes grouped under a certain supertype have all the public (inheritable) methods that the supertype has. 
  29. Three Steps of object declaration and assignment.
    • Declare a reference variable
    • Create an object
    • Link the object and the reference
    • Dog myDog = new Dog(); 
  30. True or False: With polymorphism, the reference and the object can be different.
    • True 
    • Animal myDog = new Dog();
    • With polymorphism, the reference type can be a superclss of the actual object type. 
  31. Polymorphism Examples
  32. True or False: You cannot have polymorphic arguents and return types.
    False - You can. 
  33. True or False: An overloaded method is just a different method that happens to have the same method name. It has nothing to do with inheritance and polymorphism. An overloaded method is not the same as an overriden method.
  34. True or False: By making the class as abstract, the compiler will stop any code, anywhere, from ever creating an instance of that type. 
  35. An abstract class means the class must be ___ ; an abstract method means the method must be ___ .
    • Extended
    • Overriden
  36. An abstract method has no ____ . If you delcare an abstract method, you must mark the class______.
    • Body
    • Abstract
    • You can't have an abstract method in a non-abstract class. But you can mix both abstract and non-abstract methods in teh abstract class. 
  37. True or False: The first concrete class in the inheritance tree must implement all abstract methods.