Chapter 10 from book: Inheritance

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Accessibility from within a class's package... p. 649

Access Specifier Accessible to Accessible to all a subclass other classes inside the in the same same package? package? default (no modifier) Yes Yes public Yes Yes protected Yes Yes private No No p. 649

Inheritance p. 613

Allows a new class to extend an existing class. The new class inherits the members of the class it extends. p. 613 Involves a "superclass" and a "subclass" p. 614

"fields" p. 675

An interface can contain these type of declarations. All of these types of declarations are treated as final and static. p. 675

"default methods" p. 676

An interface method that has a body. p. 676

"functional interface" p. 686

An interface that has one abstract method. p. 686

"interface" p. 669

In its simplest form, this is like a class that contains only abstract methods. It specifies behavior for a class and it is "implemented" by other classes. p. 669

Involves a "superclass" and a "subclass" p. 614

Inheritance p. 614

"superclass" p. 614

Inheritance involves a superclass and a subclass. The superclass is the general class. NOTE: Superclasses are also called "base classes". p. 614

"interface" keyword p. 669

Is used for interfaces in much the same way that the keyword "class" is used for classes. Ex. public interface InterfaceName //interface example { (method headers.....) } public class FakeClassName //class example for { // comparison (method headers......) } p. 669

"contract" p. 671

It is often said that an interface is like one of these... p. 671

"Class hierarchy" p. 655

Like a family tree, a ___ ________ shows the inheritance relationships between classes. Classes often are depicted graphically in a ___ ______. p. 655

"instanceof" p. 661

Operator in Java that can be used to determine where an object is an instance of a particular class. General form of an expression that uses the instanceof operator: refVar instanceof ClassName *Yes, the "o" in instanceof is supposed to be lowercase p. 661

"overloading" vs. "overriding" p. 639

Overloaded methods have the same names but different signatures. When a method overrides another method, they both have the same signature. p. 639 Overriding can only take place in an inheritance relationship. p. 640

"method's signature" p. 636

Recall from chapter 6 that _______consists of the method's name and the data types of the method's parameters, in the order that they appear. p. 636

True or False: Private members of the superclass cannot be accessed by the subclass. p. 620

True p. 620

True or False: When a subclass extends a superclass, the public members of the superclass become public members of the subclass. p. 622

True p. 622

The "Object Class" p. 655

What is the name of the Java API class that all other classes directly or indirectly inherit from? p. 655

"interface inheritance" p. 681

When a class implements an interface, this type of inheritance relationship is established. p. 681

"implement" keyword p. 670

When you want a class to implement an interface, you use this keyword in the class header. p. 670

Accessibility from outside the class's package... p. 649

Access Specifier Accessible to Accessible to all a subclass other classes outside the outside the same package? same package? default (no modifier) No No public Yes Yes protected Yes No private No No p. 649

"final modifiers" p. 642

A method cannot be overridden in a subclass when it is declared with these types of modifiers... p. 642

method "overriding" p. 634

Because the subclass is more specialized than the superclass, it is sometimes necessary for the subclass to replace inadequate superclass methods with more suitable ones. This is know as "method overriding". p. 634 and example from p. 636 (10-13) Written in code as "@Override" p. 637

How do you show inheritance in a UML diagram? p. 622

By connecting two classes with a line that has an open arrowhead at one end. The arrowhead points to the superclass. p. 622 and see reference to picture

Superclass or subclass constructors....which one executes first? p. 623

Superclass The superclass constructor always executes before the subclass constructor. p. 623 In an inheritance relationship, the subclass inherits members from the superclass, not the other way around. Thjis means it is not possible for a superclass to call a subclass's method. p.625

Which statement in the subclass's constructor must the superclass constructor be? p. 627

The first statement. p. 627

"binding" p. 659 and Chapter 6

The process of matching a method call with the correct method definition. p. 659

"realization relationship" p. 675

The relationship between a class and an interface. (the class realizes the interfaces) You show this type of relationship in a UML diagram by connecting a class and an interface with a dashed line that has an open arrowhead at one end. p. 675

"Abstract Methods"

These methods are used to ensure that a subclass implements the method. This type of method appears in a superclass, but expects to be overridden in a subclass. It must be overridden in a subclass.

"protected members" p. 643

These types of members of a class may be accessed by methods in a subclass, and by methods in the same package as the class. Ex. To make something "protected" you would simply write it like this: public class GradedActivity2 { protected double score; //numeric score /** The setScore method sets the score field. @parem s The value to store ion score */ public void setScore(double s) { score = s; } //more code followed this but you get the point //pay attention to "protected double score" above } p. 643

"inner class" p. 683

This class is a class that is defined inside another class. p. 683

"abstract" keyword p. 668

Defines abstract methods and abstract classes. p. 668

"polymorphism" p. 657

This is the java term for when a superclass reference variable references objects of a subclass. Polymorphism also means "the ability to take many forms". But in Java, a reference variable is polymorphic because it can reference objects of types different from its own, as long as those types are subclasses of its type. Ex. GradedActivity exam1 = new FinalExam(50, 7); p. 657/658

"super" keyword p. 626

This keyword refers to an object's superclass. You can use the "super" keyword to call a superclass constructor. p. 626

"Abstract Classes" p. 662

This type of class is not instantiated, but other classes extend it. An abstract method has no body and must be overridden in a subclass. p. 662

"is a" relationship p. 614

This type of relationship occurs when on object is a specialized version of another object. Ex. A bumblebee (has its own unique characteristics, such as the ability to sting) or a grasshopper (has its own unique characteristics, such as the ability to jump) would be a specialized version of an Insect. More Ex. A poodle is a dog. A car is a vehicle. A flower is a plant. A rectangle is a shape. A football player is an athlete. p. 614

"dynamic" binding or "late" binding p. 659

Type of "binding" that is performed when a variable contains a polymorphic reference. p. 659

"subclass" p. 614

You can think of this as an extended version of the superclass. Inheritance involves a superclass and a subclass. The subclass is the specialized class. NOTE: Subclasses are also called "derived classes". For consistency though, the text only used the terms superclass and subclass. p. 614

"lambda expression" p. 686

You can use this special type of expression to create an object that implements a functional interface. This expression can be thought of as an anonymous method. p. 686 "A way of passing a block of code to a method". - according to the youtube video: https://www.youtube.com/watch?v=q5i_O4Uj_O8

Where should the super statement be written (the one that calls the superclass constructor)? p. 627

Only in the subclass's constructor. p. 627

"anonymous inner classes" p. 683

This class is an inner class that has no name. This class must implement an interface, or extend another class. When you want a class to be simple, and to be instantiated only once in your code. p. 683

"extends" key word p. 619

This header keyword indicates that the class (whose header the keyword was in) extends another class (a superclass). p. 619

True or False: A superclass can also inherit from another class. p. 649

True p. 649


संबंधित स्टडी सेट्स

Modules 17 – 20: Introduction to Cisco Networking Group Exam

View Set

Chapter 11: Drug Therapy in Older Adults (Evolve, Kahoot, PPT)

View Set

Psychiatric/ Mental Health Drugs (Pharmacology)

View Set

Chapter 13 AP Gov Vocabulary Terms

View Set

Financial Literacy II (part 2 financial terms)

View Set

Ch-27 (10) The Money and Banking

View Set