Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Module 7 Mastery Check

wolvesled edited this page Sep 5, 2013 · 1 revision
  1. Does a superclass have access to the members of a subclass? Does a subclass have access to the members of a superclass? Answer: No, superclass does not have access to the members of a subclass unless the member is subclass is static, or public member can be access through an object of the subclass. But subclass can have access to non-private superclass members directly.
  2. Create a subclass of TwoDShape called Circle. Include an area() method that computes the area of the circle and a constructor that uses super to initialize the TwoDShape portion.
  3. How do you prevent a subclass from having access to a member of a superclass? Answer: using private accessor keyword to declare that member in the superclass.
  4. Describe the purpose and use of both versions of super. Answer: use super() to call constructor of superclass within sub-class constructor. use super.member to call hidden member from superclass within subclass definitions.
  5. Given the following hierarchy: class Alpha { ... class Beta extends Alpha { ... class Gamma extends Beta { ... In what order are the constructors for these classes called when a Gamma object is instantiated? Answer: Alpha -> Beta -> Gamma.
  6. A superclass reference can refer to a subclass object. Explain why this is important as it relates to method overriding. Answer: It implements dynamic method dispatch for Java which is very important feature for Object-Oriented programming - runtime polymorphism. It allows the runtime to decide to use which version of the overriding method by specific type of object the superclass reference referred to.
  7. What is an abstract class? Answer: a class contain one or more abstract method(s) - that must be implemented in inheriting classes.
  8. How do you prevent a method from overridden? How do you prevent a class from being inherited? Answer: using the final keyword precede the method name or the class name when declare.
  9. Explain how inheritance, method overriding, and abstract class are used to support polymorphism. Answer: First, you can inheriting a class by extend from it, that you have all the members of the inheriting class that at use of the subclass. Then you can declare a method in subclass with the same signature and return type with the superclass method to override it. That way, until an object is instantiated, there can tell which version of the defining method to use upon a method call of the same name. Also, inheriting allows the superclass reference to be assigned with a subclass object, so, calling the same method act differently depend on the type of the subclasses. Abstract class declares the common methods for the subclasses to implement, which forces method override in subclass. That way, you can use a polymorphic array of the superclass reference upon variety of subclass objects but querying the same method interface, and the runtime dispatches to the corresponding method of each object. Which is one interface, multiple form polymorphism.
  10. What class is a superclass of every other class? Answer: the Object class.
  11. A class that contains at least one abstract method must, itself, be declared abstract. True or False? Answer: True.
  12. What keyword used to create a named constant? Answer: the final keyword.

Clone this wiki locally

Morty Proxy This is a proxified and sanitized view of the page, visit original site.