generated from nus-cs2030/base-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Lecture 3 Summary (Polymorphism)
Bacon-Strips edited this page Oct 12, 2021
·
1 revision
- if S is a subclass of T, object of type S can replace type T objects without changing the desirable property of the program.
- Many forms
- Sub-type can be passed in as arguments for super-type parameters
- You can convert from sub-type to super-type but not other way round
- The type in which the variable is declared
- Restricts the methods it can call during compilation
- The type of the object that the variable is point to
- Determines the actual method called during runtime
A variable's compile-type is determined at compile time; its run-time type varies depending on object assigned to it
- Comparing two objects using the == operator returns true only if both refers to the same object instance
(Same for the inherited Object.equals(Object) method)
- However, for String objects, the == compares if the String objects are the same instance while the String.equals method compares if the String content is the same
Same method name different argument type. Will be called when the method is called with the corresponding argument type
The compile-time type decides which overloaded method to call during compilation
Same method name and argument types. Will be the method called during run-time.
Exact method to invoke is not known until runtime
Peer Learning
Guides
Setting Up Checkstyle
Setting Up Java
Setting Up MacVim
Setting Up Stu
Setting Up Unix For Mac
Setting Up Unix For Windows
Setting Up Vim
Setting up SSH Config
SSH Without Password
Copying Files From PE Nodes
Using tmux
CS2030 Contents
Lecture 1 SummaryLecture 2 Summary
Access Modifiers
Lecture 3 Summary (Polymorphism)
Compile Time Type VS Runtime Type
Abstraction, Encapsulation, Inheritance, and Polymorphism
SOLID Principles
Class VS Abstract Class VS Interface
Comparable VS Comparator
Generic Types T
HashMap
Raw Types with Generic
Lambda expression
PECS (Producer Extends Consumer Super)
Optional
Streams
Parallel Streams
Monad
Functors and Monads with Category Theory