¡GoConqr estrena diseño! Cuéntanos qué te parece.

Fichas

Inheritance

Virginie Gagné Computer Science Inglés 23 fichas

Inheritance

Fichas del conjunto (23)

  1. 1define subclass...When we define a subclass, we say that the subclass “extends” the superclass. The superclass is often called the base class or parent class. The subclass is often called derived class or extended class.
  2. 2a subclass inherits...the fields and methods of the superclass, namely by default the subclass automatically has the same field and methods as the superclass.
  3. 3Constructor methods... Why?Constructor methods are not inherited, cuz each object is an instance of a unique class.
  4. 4how to do constructor chaining?The first line of any constructor is
    super(...); // possibly with parameters
    If you leave this line out, then the Java compiler puts in the following with no parameters:
    super();
  5. 5overriding vs overloadingWhen a subclass method and superclass method have the same method name and the same number, types, and order of parameters, then we say that the subtype method overrides the supertype method. When the method name is the same but the type, number, or order of parameters changes, then we say the method is overloaded.
    Note that the return type doesn’t play a role in either overriding or overloading
  6. 6define the final modifierThe final modifier provides some flexibility on when we can extend classes or not.
    Methods in a class can also be final. (cant override them)
    final variable means we cant modify it after (compiler error)
  7. 7define the Java Object classdefine the Java Object class
  8. 8conditions for clone() to be truex == x.clone() should return false
    x.equals( x.clone()) should returns true
  9. 9If Beagle and Dog were in different packages, then...we would need to add a public modifier to both the class Dog as well as the field name. We would also need to add an import statement to Beagle,
    import package1.Dog;
    so that the compiler knows where to find the Dog class.
  10. 10What if we were to put a private modifier on the name field of Dog?we would get a compiler error in Beagle, since name field would not visible in Beagle. A Beagle object would still have the field name. The problem is that the name is not accessible.
    “The subclass does not
    inherit the private members of its parent class.”
    Rather than accessing the field by its name, a Beagle object has to access it using getters and setters.
  11. 11why use instanceof operator?to check if an object is an instance of a particular class
    instanceof operator takes two arguments: the first is a referencetype variable var; the second is a class C, ie.
    var instanceof C
  12. 12define an interfaceAn interface is a Java program component that is like a class, but it doesn’t contain the bodies of the methods.
  13. 13We say that a class implements an interface if...... if the class implements each method that is defined in the interface. In particular, the method signatures must be the same as in the interface.
  14. 14where do Java interfaces fit into the class hierarchy?where do Java interfaces fit into the class hierarchy?
  15. 15define abstract classuse a hybrid of a class and an interface in which some methods are implemented but other methods are specified only by their signature
    add the modifier abstract to the definition of the class AND to each method that is missing a body
  16. 16a subclass extends... a class can implement.... an interface can extend...a subclass extends... a class can implement.... an interface can extend...
  17. 17define polymorphismThis property, that the object type can be narrower than the declared type, is called polymorphism.
    When we discuss polymorphism, we assume a program has compiled fine, and we are concerned with which method is invoked at runtime. The method is determined by the class that the object belongs to.
  18. 18define Java Comparable interfaceinterface Comparable {
    int compareTo( T t );
    }
  19. 19Java API recommends e1.compareTo(e2) returns:negative number, if e1 < e2
    0, if e1.equals(e2) is true
    positive number, if e1 > e2
    Note “>” and “<“ here do not refer to a Java operation, but rather to
    our model (in our heads) of the ordering.
  20. 20the enhanced for loop makes use of...two interfaces: Iterator and Iterable
  21. 21define Iterator interfacedefine Iterator interface
  22. 22Implement s l l iteratorImplement s l l iterator
  23. 23We say “a class is iterable” if ...We say “a class is iterable” if it can make/construct an Iterator object that can iterate over its elements.

Información

Descripción
Computer Science Fichas sobre Inheritance, creado por Virginie Gagné el 18/04/2022.
Creado por
Virginie Gagné
Visitas
0
Valoración

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?