MODULE 3 (Week 4) Polymorphism Flashcards
Describes situations in which something occurs in several different forms
Describes the concept that you can access objects of different types through the same interface. Each type
can provide its own independent implementation of this interface.
Polymorphism
Why is polymorphism used in Java?
It makes it possible to write a method that can correctly process different types of functionalities that have the same name
Consistency can be gained in a code by using polymorphism
Advantages of Polymorphism in Java
It provides reusability to the code.
A single variable can be used to store multiple data values.
With lesser lines of code, it becomes easier for the programmer to debug the code.
A class has multiple methods having the same name but different in parameters
Method Overloading
Where is method overloading performed?
Within a class
Three ways to overload methods in Java:
By changing number of arguments
By changing the data type
By changing both number of arguments and data type
A situation that occurs when the compiler cannot determine which method to use
Ambiguous situations
Methods with identical names that have identical argument lists but different return types
Illegal methods
An object’s memory address
Is implicit - is automatically understood without actually being written
Reference
The reference to an object
Passed to any object’s non-static class method
A reserved word in Java
Does not need to be used in methods you write in most situations
Use to make classes work correctly
This reference
A this reference is implicitly received by what type of methods?
Instance methods
When a this referenced is used with a field name in a class method, the reference is to what?
To the class field instead of to the local variable declared within the method
In using static fields, this type of methods do not have the this reference and have no object associated with them
Class methods
In using static fields, this type of variables are shared by every instantiation of a class and only has one copy per class
Class variables