Lecture 20/21 - Programming with Objects/Inhertiance and the Implementation of Polymorphism

studied byStudied by 0 people
0.0(0)
learn
LearnA personalized and smart learning plan
exam
Practice TestTake a test on your terms and definitions
spaced repetition
Spaced RepetitionScientifically backed study method
heart puzzle
Matching GameHow quick can you match all your cards?
flashcards
FlashcardsStudy terms and definitions

1 / 9

encourage image

There's no tags or description

Looks like no one added any tags here yet for you.

10 Terms

1

Classes in Java

  • every class is a subclass of some other class (except for one)

  • the “Object” class defines several instance method that are inherited by every other class

  • toString() method, when you create a class u can write a new toString() method, when using the toString() if you concatat the object to a string it will automatically call the toString method

New cards
2

Designing a class to play the Card higher lower game

  • objects candidates

    • game, player, hand, card, deck, value, suit

      • card and deck are most obviously reusable

  • verbs that involed are the mthode

    • shuffle, deal, add remove card

New cards
3

BlackJackHand Class

  • extend the original hand class but include extra functionality

  • getBlackJackValue()

New cards
4

Inheritance

  • refers to the fact that one class can inherit part of or all of its structure and behavior from another class

  • Class A is the superclass, Class B is the subclass

  • Class B inherits from class A

  • Multiple Classes can be declared as subclasses of the super class

  • subclasses can be referred to as sibling class

New cards
5

Protected Acess

  • when you declare a method or member variable to be protected, you are saying that is part of the implementation of the class instead of the public interface

  • allows subclasses to reuse and modify that part of the implementation

New cards
6

Overriding an Inherited Method

  • the toString() method is designed to be overridden

  • provides customizable string representation of the objects in that subclass

New cards
7

Polymorphism

  • a method is polymorphic is the action performed by the method depends on the actual type of the object

New cards
8

Overriding

  • run time polymorphism

  • occurs between two classes using inheritance

  • array elements are stored in contiguous locations, making it easy to determine relative location of elements

  • methods involved must have the same name and same signature

  • at runtime java determines the actual object type and invokes the most specific overridden method

New cards
9

Overloading

  • compile time polymorphism

  • occurs within the class

  • insertion and deletion operations are slow as elements are supposed to be stored sequentially index wise

  • methods involved must have the same name but different signatures

New cards
10

Dynamic Dispatch

  • allows the selection of methods at runtime based on the actual object type rather than the reference type

New cards
robot