Java : Inheritance (9)
the following points about *abstract methods* & *classes* include:
(656)
general format of an *abstract method header* [code]
*AccessSpecifier abstract ReturnType* *MethodName(ParameterList);* (651) OR public abstract void Name(int value);
difference between *protected access* & *package access* include:
*Protected members* can be accessed by methods in the same package or in a subclass. This is true even if the subclass is in a different package. Members with *package access*, cannot be accessed by subclasses that are in a different package (638)
FACT
*inheritance* involves a superclass and a subclass (606)
package access [code]
*public class Circle {* -->*double radius;* -->*int centerX, centerY;* -->(Method definitions follow ... ) *}* (637)
method header using the *final modifier* [code]
*public final void message()* (632)
general format of an *interface definition*: [code]
*public interface InterfaceName {* -->*(Method headers...)* *}* (657)
general form of an expression that uses the *instanceof operator* [code]
*refVar instanceof ClassNeme*
a subclass may call an overridden superclass method by prefixing its name with the _____ and a ______
*super key word* and a *dot [ . ]* (627)
the Java API has a class named _____, which all other classes directly or indirectly inherit from
Object (644)
Table 9-3 Accessibility from within the class's package
Table 9-3 Accessibility from within the class's package (638)
Table 9-4 Accessibility from outside the class's package
Table 9-4 Accessibility from outside the class's package (638)
FACT
a class can directly inherit from only 1 superclass, but Java allows a class to implement multiple interfaces (662)
FACT
a method in a subclass can *overload* a method in the superclass (629)
abstract method
a method that appears in a superclass, but expects to be overridden in a subclass; has only a header and no body (651)
what does the *toString* [in the Object class] method return
a string containing the object's class name, followed by the @ character, followed by the object's hexadecimal hashcode (645)
CONCEPT
a superclass can also *inherit* from another class ( 639)
a(n) _____ class is not instantiated, but other classes inherit from it. A(n) _____ method has no body and must be overridden in a subclass
abstract (651)
a(n) _____ is not instantiated itself, but serves as a superclass for other classes
abstract class (651) ~the abstract class represents the generic or *abstract form* of all the classes that inherit from it
a class becomes *abstact* when you place the _____ key word in the class definition
abstract key word (651)
when a class contains a(n) _____, you cannot create an instance of the class
abstract method (651) ~abstract methods are commonly used in abstract classes
what does the *equals method* accept?
accepts the address of an object as its argument and returns true if it is the same as the calling object's address (645)
in an *inheritance relationship*, the superclass constructor _____ executes before the subclass constructor
always (614)
CONCEPT
an *interface* specifies *behavior* for a class (657)
what is an object's hashcode?
an integer unique to the object (645)
FACT
an interface reference variable can reference any object that implements that interface, regardless of its class type (663) ~another example of *polymorphism*
FACT
any class that inherits from the class, or is in the same package, has unrestricted access to the protected member (637)
FACT
because every class directly or indirectly inherits from the *Object* class, every class inherits the Object class's members (645) 2 of the most useful include: -->1. *toString* method -->2. *equals* method
it is always better to make all fields _____ and then provide public methods for accessing those fields
private (637)
when an object of the subclass is created, the _____ of the superclass exist in memory, but only _____ in the superclass can access it
private members & methods (611)
FACT
private members of the superclass cannot be accessed by the subclass, so they are technically *not inherited* (611)
the relationship between a class and an interface is known as a(n) _____
realization relationship [the class realizes the interfaces] (662)
a subclass may have a method with the same _____ as a superclass method. In such case, the subclass method overrides the supercalss method
signature (624)
FACT
sometimes a subclass *inherits* a method from it superclass, but the method is inadequate for the subclass's purpose (624)
FACT
sometimes it is desirable to establish a *chain of inheritance* in which one class inherits from a second class, which in turn inherits from a third class (639)
the _____ is the specialized class
subclass or derived class (606)
the name of the _____ is listed after the word *extends*
superclass (611)
the _____ is the general class
superclass or base class (606)
FACT
the *is a relationship* does not work in reverse. (649)
CONCEPT
the *super* key word refers to an object's *superclass* -you can use the *super* key word to call a *superclass constructor* (616)
what is the use of abstract methods?
to ensure that a subclass implements the method (651)
FACT
to show a realization relationship in a UML diagram, connect a class and an interface with a dashed line with an open arrowhead at 1 end [points to the interface] (662,663)
FACT
to specify multiple interfaces in a class definition, simply list the names of the interfaces, seperated by commas, after the *implements key word* (662)
FACT
when a class *implements an interface*, it must provide all of the methods that are listed in the interface, with the exact signatures specified (658) ~aka override all of the methods specified by the interface ~the methods must have the same return type specified in the interface
FACT
when a class *inherits* from another class, the public members of the superclass become public members of the subclass (613)
FACT
when a subclass overloads a superclass method, both methods can be called with a subclass object. However, when a subclass overrides a superclass method, only the subclass's version of the method can be called with a subclass object (629)
FACT
when a superclass variable references a subclass object, a potential problem exists (647)
FACT
when an *is a relationship* exists between objects, it means that the specialized object has all of the characteristics of the general object, plus additional characteristics that make it special (60)
FACT
when an abstract method appears in a class, the method must be overridden in a subclass. If a subclass fails to override the method, an error will result. (651)
FACT
when an interface variable references an object, you can use the interface variable to call *only* the methods that are specified in the interface (668)
is a relationship
when one object is a specialized version of another object (606)
FACT
you cannot create an instance of an interface (668)
FACT
you should avoid making a class member *protected* when possible (637)
FACT
a *protected member* can be accessed by some methods outside the class (632)
CONCEPT
a *reference variable* can reference objects of classes that inherit from the variable's class (646)
FACT
a *subclass8 is an extension of its *superclass* (611)
Java : Inheritance (605-669)
Java : Inheritance (605-669)
the term _____ means the ability to take many forms
polymorphism (647)
the distinction between *overloading* & *overriding* include:
1. if 2 methods have the same name, but different signatures, they are *overloaded*. This is true where the methods are in the same class or where 1 method is in the superclass and the other method is in the subclass 2. if a method in a subclass has the same signature as a method in the superclass, the subclass method overrides the superclass method (629)
important issues that you should remember about constructors in an *inheritance relationship* include:
1. the superclass constructor *always executes before the subclass constructor* 2. you can write a *super* statement calling a superclass constructor, but only in the subclass's constructor. You cannot call the superclass constructor from any other method 3. if a *super statement* that calls a superclass constructor appears in a subclass constructor, it *must* be the first statement 4. if a *subclass* constructor *does not* explicitly call a superclass constructor, Java will automatically call *super()* just before the code in the subclass's constructor executes 5. if a *superclass does not* have a default constructor & *does not* have a no-arg constructor, then a class that inherits from it *must* call 1 of the constructors that the superclass *does* have (622, 623)
CONCEPT
Inheritance allows a new class to be based on an existing class ~the new class inherits the members of the class it is based on (605)
classes often are depicted graphically in a _____
class hierarchy (644) ~shows the inheritance relationships among classes ~more general classes are toward the top ~the more specialized classes are toward the bottom
show *inheritance* in a *UML diagram*
connect 2 classes with a line that has an *open arrowhead* at one end (613) ~*arrowhead* points to the superclass
FACT
even though a subclass may override a method in the superclass, superclass objects still call the superclass version of the method (629)
when a class does not use the *extends key word* to *inherit* from another class, Java automatically _____ it from the *Object* class
extends (644)
the subclass inherits _____ from the superclass without any of the being rewritten
fields and methods (606) ~new fields and methods can be added tot he subclass to make it more specialized than the superclass
an interface can contain field declarations, but all fields in an interface are treated as _____ and _____
final and static (662)
when a method is declared with the _____ modifier, it *cannot be overridden* in a subclass
final modifier (632)
FACT
if a subclass attempts to override a *final method*, the compiler generates an error (632) ~this technique can be used to make sure that a particular superclass method is used by subclasses and not a modified version of it (632)
FACT
in an *inheritance relationship*, the subclass *inherits* members from the superclass, *not* the other way around (615) ~this means it is *not possible* for a superclass to call a subclass's method
FACT
in order for a class to use an *interface*, it must *implement the interface* with the *implements key word* (658)
*extends* key word
indicates that this class *inherits* from another class [a superclass] (611)
every class in Java, including the ones in the API and the classes that you create, directly or indirectly _____from a class named *Object*, shich is part of the *java.lang* lackage
inherit (644)
in *object oriented programming*, _____ is used to create an *is a relationship* among classes
inheritance (606) ~allows you to extend the capabilities of a class by creating another class that is a specialized version of it
both *overloading* and *overriding* can take place in an ______
inheritance relationship (629)
there is an operator in Java named _____ that you can use to determine whether an object is an (is a relationship) instance of a particular class
instanceof (649)
a(n) _____ looks similar to a class, except the key word *interface* is used instead of *class*, and the methods that are specified in a(n) _____ have *no bodies, only headers that are terminated by semicolons [ ; ]*
interface (657)
a(n) is similar to an *abstract class* that has all *abstract methods* -it cannot be instantiated, and all of the methods listed in a(n) _____ must be written elsewhere. -the purpose is to specify *behavior for other classes*
interface (657)
when a class implements an interface, an inheritance relationship known as _____ is established
interface inheritance (666)
why is the distinction between overloading and overriding important?
it can affect the accessibility of superclass methods in a subclass (629)
FACT
it is more likely that you will give *package access* to class members by accident than by design, because it is easy to forget the *access specifier* (638)
abstract classes are drawn like regular classes in UML, except the name of the class and the names of abstract methods are shown in _____
italics (657)
FACT
java performs *dynamic binding* or *late binding* when a variable contains a polymorphic reference. ~the JVM determines at runtime which method to call, depending on the type of object that the variable references. ~it is the object's type that determines which method is called, not the variable's type (648)
FACT
just as you can create reference variables of a class type, Java allows you to create reference variable of an interface type (663)
because the subclass is more specialized than the superclass, it is sometimes necessary forthe subclass to replace inadequate superclass methods with more suitible ones. this is known as _____
method overriding (624)
if a superclass *does not* have a default constructor & *does not* have a no-arg constructor, then a class that *inherits* from it _____ call one of the constructors that the superclass *does have*. It it *does not*, an error will result when the subclass is compiled
must (622)
there is a distinction between _____ and _____ a method
overloading and overriding a method (629) ~overloading: same name; different signature ~overriding: both have the same signature
FACT
overriding can take place *only* in an*inheritance relationship* (629)
*protected members* of a class can be accessed by methods in a subclass, and by methods in the same _____ as the class
package (632)
if you *do not* provide an *access specifier* for a class member, the class member is given _____ by default. This means that any method in the same package can access the member
package access (637)
in Java, a reference variable is _____ because it can reference objects of types different from its own, as long as those types are related to its type through inheritance
polymorphic (647)