Abstract Class

Cards (82)

  • All variables and methods of a parent class, even private members, are inherited by its children
  • Private members cannot be referenced by name in the child class
  • Private members inherited by child classes exist and can be referenced indirectly
  • Because the parent can refer to the private member, the child can reference it indirectly using its parent's methods
  • The super reference can be used to refer to the parent class, even if no object of the parent exists
  • Taking the time to create a good software design reaps long-term benefits
  • Inheritance issues are an important part of an object-oriented design
  • Properly designed inheritance relationships can contribute greatly to the elegance, maintainability, and reuse of the software
  • Every derivation should be an is-a relationship
  • Think about the potential future of a class hierarchy, and design classes to be reusable and flexible
  • Find common characteristics of classes and include them as high in the class hierarchy as appropriate
  • Override methods as appropriate to tailor or change the functionality of a child
  • Add new variables to children, but don't redefine (shadow) inherited variables
  • Allow each class to manage its own data;
    use the super reference to invoke the parent's constructor to set up its data
  • Even if there are no current uses for them, override general methods such as toString and equals with appropriate definitions
  • Use abstract classes to represent general concepts that lower classes have in common
  • Use visibility modifiers carefully to provide needed access without violating encapsulation
  • The final modifier can be used to curtail inheritance
  • If the final modifier is applied to a method, then that method cannot be overridden in any descendant classes
  • If the final modifier is applied to an entire class, then that class cannot be used to derive any children at all 

    Thus, an abstract class cannot be declared as final
  • Polymorphism means "many forms", and it occurs when we have many classes that are related to each other by inheritance.
  • Inheritance lets us inherit attributes and methods from another class.
  • Polymorphism uses those methods to perform different tasks. 

    This allows us to perform a single action in different ways.
  • Data abstraction is the process of hiding certain details and showing only essential information to the user.
  • Abstraction can be achieved with either abstract classes or interfaces
  • The abstract keyword is a non-access modifier, used for classes and methods
  • Abstract class
    is a restricted class that cannot be used to create objects (to access it, it must be inherited from another class).
  • Abstract method
    • can only be used in an abstract class, and it does not have a body.
    • The body is provided by the subclass
  • An abstract class can have both abstract and regular methods
  • An abstract class is a placeholder in a class hierarchy that represents a generic concept (concept that applies to all descendants)
  • Provides a conceptual view of the entity
    represented.
    Abstract classes
  • An abstract class cannot be instantiated
  • The modifier abstract is used on the class header to declare a class as abstract.
  • Why And When To Use Abstract Classes and Methods?
    To achieve security
    • hide certain details and only show the important details of an object.
  • A java interface specifies functionality that a class must support
  • A Java interface is a collection of abstract methods and constants
  • An abstract method can be declared using the modifier abstract, but because all methods in an interface are abstract, usually it is left off
  • An interface is a completely "abstract class" that is used to group related methods with empty bodies.
  • An interface is used to establish a set of methods that a class will implement
  • To access the interface methods, the interface must be "implemented" by another class with the implements keyword.