Level 108 Level 110
Level 109

[Quiz] Inheritance


107 words 0 ignored

Ready to learn       Ready to review

Ignore words

Check the boxes below to ignore/unignore words, then click save at the bottom. Ignored words will never appear in any learning session.

All None

Ignore?
inheritance
allows a class to be a subclass of a superclass and thereby inherit public and protected variables and methods of the superclass. A parent/child relationship.
Unified Modeling Language (UML)
A graphical language used by programmers and analysts to describe classes and object-oriented processes.
Base class
A class that is used as a basis for inheritance.
Derived class
A subclass.
composition
Represents real-world whole-part relationships, e.g., an engine is a part of a car
Aggregation
A type of composition in which a class contains one or more members of another class that would continue to exist without the object that contains them.
Superclass
Base class
Subclass
a class that represents a specialization of another.
Parent class
Base class
Child class
Derived class
extends
What keyword at the beginning of a class creates a subclass?
instanceof operator
The instanceof operator determines whether an object that is the operand on the left is a member or descendant of the class that is the operand on the right.
Upcast
To upcast an object is to change it to an object of a class higher in the object's inheritance hierarchy.
Polymorphism
describes the way an object or variable my be treated in different contexts as though it was a different type. For example: inheritance allowes an argument of type B to be passed to a param…
Override a method
To override a method in a parent class is to create a method in a child class that has the same name and parameter list as a method in its parent class.
Subtype polymorphism
The ability of one method name to work appropriately for different subclasses of a parent class.
super
Similar to the "this" keyword you can use the _______ keyword to refer directly to a superclass
Information hiding
Concealing certain details of an object from other objects so as to not adversely affect them.
Fragile
Fragile classes are those that are prone to errors.
Virtual method calls
Those in which the method used is determined when the program runs, because the type of the object used might not be known until the method executes. In Java, all instance method calls are virtual calls by default.
Inlining
Inlining the code is an automatic process that optimizes performance. Because a final method's definition can never be overridden, the compiler can optimize a program's performance by removing the calls to final methods and repla…
is a relationship
when one object is a specialized version of another object (606)
inheritance (606)
in *object oriented programming*, _______ is used to create an *is a relationship* among classes
superclass or base class (606)
the _______ is the general class
subclass or derived class (606)
the _______ is the specialized class
fields and methods (606)
the subclass inherits _______ from the superclass without any of the being rewritten
extends key word
indicates that this class *inherits* from another class [a superclass] (611)
superclass (611)
the name of the _______ is listed after the word *extends*
private members
when an object of the subclass is created, the _______ of the superclass exist in memory, but only _______ in the superclass can access it
show *inheritance* in a *UML diagram*
connect 2 classes with a line that has an *open arrowhead* at one end (613)
always (614)
in an *inheritance relationship*, the superclass constructor _______ executes before the subclass constructor
must (622)
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*…
signature (624)
a subclass may have a method with the same _______ as a superclass method. In such case, the subclass method overrides the supercalss method
method overriding (624)
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 _______
super key word and a dot [ . ] (627)
a subclass may call an overridden superclass method by prefixing its name with the _______ and a _______
overloading and overriding a method (629)
there is a distinction between _______ and _______ a method
inheritance relationship (629)
both *overloading* and *overriding* can take place in an _______
why is the distinction between overloading and overriding important?
it can affect the accessibility of superclass methods in a subclass (629)
final modifier (632)
when a method is declared with the _______ modifier, it *cannot be overridden* in a subclass
public final void message() (632)
method header using the *final modifier* [code]
package (632)
protected members of a class can be accessed by methods in a subclass, and by methods in the same _______ as the class
private (637)
it is always better to make all fields _______ and then provide public methods for accessing those fields
package access (637)
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 [code]
public class Circle {
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.
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)
class hierarchy (644)
classes often are depicted graphically in a _______
Object (644)
the Java API has a class named _______, which all other classes directly or indirectly inherit from
inherit (644)
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
extends (644)
when a class does not use the *extends key word* to *inherit* from another class, Java automatically _______ it from the *Object* class
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)
what is an object's hashcode?
an integer unique to the object (645)
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)
polymorphism (647)
the term _______ means the ability to take many forms
polymorphic (647)
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
instanceof (649)
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
refVar instanceof ClassNeme
general form of an expression that uses the *instanceof operator* [code]
abstract (651)
A(n) _______ method has no body and must be overridden in a subclass
abstract method
a method declared in a class or an interface without a method body
AccessSpecifier abstract ReturnType MethodName(ParameterList); (651)
general format of an *abstract method header* [code]
what is the use of abstract methods?
to ensure that a subclass implements the method (651)
abstract method (651)
when a class contains a(n) _______, you cannot create an instance of the class
abstract class (651)
a(n) _______ is not instantiated itself, but serves as a superclass for other classes
abstract key word (651)
a class becomes *abstact* when you place the _______ key word in the class definition
-656
the following points about abstract methods & classes include:
italics (657)
abstract classes are drawn like regular classes in UML, except the name of the class and the names of abstract methods are shown in _______
interface (657)
-the purpose is to specify *behavior for other classes*
public interface InterfaceName {
general format of an *interface definition*: [code]
final and static (662)
an interface can contain field declarations, but all fields in an interface are treated as _______ and _______
realization relationship [the class realizes the interfaces] (662)
the relationship between a class and an interface is known as a(n) _______
interface inheritance (666)
when a class implements an interface, an inheritance relationship known as _______ is established
object
instance of a class. A software bundle of related variables and methods used to model real world objects. It has 2 defining characteristics - STATE and BEHAVIOR. State is stored as variables and behavior is represented using methods
Instance Variables
Variables declared outside of any method definitions and are not modified by the "static" keyword
class variables
Variables that apply to a class as a whole , rather than a particular object of that class. Declared using the "static" keyword
return
Ends execution of a method and possibly returns a value to the calling code.
class methods
methods that cant use the "this" keyword :
defined
We would say a variable that can only be used inside the block in which it
}
Define a class called MyClass that extends MySuperclass and implements Yourinterface.
static
Indicates that a variable or method belongs to a class, rather than to any object created from the class.
main method
public static void main(String[] arguments) { }
Inheritance is used to place common code in a base class.
interacts, interfaces, knowledge
There are a number of situations in software engineering when it is important for disparate groups of programmers to agree to a "contract" that spells out how their software _______. Each group should be …
interface, methods
For example, imagine a futuristic society where computer-controlled robotic cars transport passengers through city streets without a human operator. Automobile manufacturers write software (Java, of course) that operates the automobile—stop, start, accelerate, turn left,…
reference, class
In the Java programming language, an interface is a _______ type, similar to a _______, that can contain only constants, method signatures, and nested types
constants, method signatures, nested types
In the Java programming language, an interface is a reference type, similar to a class, that can contain only c_______, m_______, and n_______
No
can you have a static final declaration in a static method
Yes
Can a class implement multiple interfaces.
implemented, extended
Interfaces cannot be instantiated—they can only be _______ by classes or _______ by interfaces.
classes, interfaces
Interfaces cannot be instantiated—they can only be implemented by _______ or extended by _______.
int turn(int intiger1);
public interface OperateCar {
public interface Hello {}
make a public interface called Hello:
function1
public interface OperateCar {
public class Class1 implements InterfaceGo{}
Write a public class "Class1" that implements the interface "InterfaceGo"
private class GoClass implements InterfaceForClass{}
Write a private class "GoClass" that implements the interface "InterfaceForClass"
Interface:
methods, end-user, interface
class hierarchy
Interfaces have another very important role in the Java programming language. Interfaces are not part of the _______, although they work in combination with classes.
Interfaces
Similar to an abstract class except all its methods are implicitly abstract which means they must be implemented by the class that "implements" the interface. A class can implement as many Interfaces as it li…
public interface Interface1 extends Interface1, Interface2, Interface3{}
Type a public interface called Interface1 that extend Interface1, Interface2 and Interface3.
public
Accessible by any class in the program.
public, static, final
All constant values defined in an interface are implicitly _______, _______, and __.
inherit, methods, class, interface
Using an interface rather than inheritance to specify a certain set of methods allows a class to _______ from some other class in other words, if a class needs two different sets of _______…
class, hidden
An interface is like a _______ where ther internal structure and some of the behavior is _______
super.printMethod();
public class Superclass {
super(startCadence, startSpeed, startGear);
public MountainBike(int startHeight,
super();
The syntax for calling a superclass constructor is:
no-argument
With super(), the superclass _______constructor is called