CS15 - Inheritance and Polymorphism

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall with Kai
GameKnowt Play
New
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/15

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

16 Terms

1
New cards

Interface

groups declarations of similar capabilities of different classes together, declare but do not define their methods, cannot be instantiated, formal contracts and ensure consistency

model an “acts-as” relationship

2
New cards

implement

key work in class call to connect to interface, contracts that classes agree to to define all the methods declared in said interface

3
New cards

@Override

put above method signature, an annotation - a signal to the compiler (and to anyone reading the code), allows compiler to enforce that interface actually has method declared

4
New cards

method signature

states the public/private, return type, nameOfMethod, and the parameter type and parameter name is there is one

5
New cards

Polymorphism

direct definition: “many forms”

a way of coding generically; reference instances of classes that share one or more methods as one generic type

treats multiple classes as their generic type while still allowing specific method implementations for specific subclasses to be executed

eg. cars and bikes can both move() → refer to them as classes of type Transporter

es. Transporter durusCar = new Car();

6
New cards

Actual type

part of polymorphism, ensures specificity

the class that the Java compiler will look for the definition of any methods, even though they are considered instances of the type of the interface 

7
New cards

Declared type

can reference many classes using one generic type

compiler will limit any caller so it can only call methods on instances that are declared as instances of interface type AND only the methods are declared in that interface

es. move() in the Transporter interface is the only method called

8
New cards

Inheritance

models an “is-a” relationship, a way of modeling very similar classes and facilitating code reuse

hierarchical relationship, assures that all subclasses of a superclass will have the superclass’ public capabilities (i.e., code) automatically – no need to re-specify

eg. Poodle is a Dog, but not every Dog is a Poodle

9
New cards

Superclass/Parent Base 

A class that is inherited from

10
New cards

Subclass/child/derived

A class that inherits from another, can only inherit from one superclass

inherits all its parent’s public capabilities

11
New cards

subclass extension

extends superclass by adding new methods (the subclass should define specialized methods)

overriding inherited methods

defining abstract methods (superclass declares but does not define all methods)

12
New cards

extends

means “is a subclass of” or “inherits from”, lets the compiler know that subclass is inheriting from superclass,

eg. extends <superclass name>

13
New cards

Partially Override Methods

partially accept the inheritance relationship

Step 1: use @override to signal to compiler

Step 2 : declare method with same name and return type as super class

Step 3: refer to parent class method using super.<methodName>, signals to invoke original inherited method

Step 4: add something specialized

14
New cards

lowest common denominator

in the hierarchical system, the most recent superclass that all the subclasses have in common

15
New cards

super()

parent’s constructor,

called from the subclasses’s constructor to make sure the superclass’s instance variables are initialized properly

allows us to access to superclasses private instance variables

only called once, first line of subclass’s constructor

16
New cards

abstract method

declared in the superclass, but not defined - it is up to the subclasses to father down hierarchy to provide their own implementations

used when subclasses can’t really re-use any implementation that the superclass provides

eg. all Cars should loadPassengers, but each subclass will loadPassengers very differently

use @Override

eg. public abstract void loadPassanger();

Explore top flashcards

CGT 163 Exam 1
Updated 967d ago
flashcards Flashcards (81)
Chapter 1 & 2
Updated 231d ago
flashcards Flashcards (65)
Body Mechanics
Updated 197d ago
flashcards Flashcards (34)
Biology term 1 y9
Updated 883d ago
flashcards Flashcards (49)
CGT 163 Exam 1
Updated 967d ago
flashcards Flashcards (81)
Chapter 1 & 2
Updated 231d ago
flashcards Flashcards (65)
Body Mechanics
Updated 197d ago
flashcards Flashcards (34)
Biology term 1 y9
Updated 883d ago
flashcards Flashcards (49)