2110 Flashcards
(26 cards)
Does an abstract class need to be instantiated?
No - it just defines variables t methods these methods can
Also be abstract
Do subclasses of an abstract class need to inherit variables & methods of their superclass?
Yes
Which class type i just a header and no body?
An abstract class
Abstract class syntax
What is an interface
Just a collection of method declaration • no data no body
How does a class implement an interface
It guarantees to use all the methods! Therefore an interface enforces an API in software design
Interface syntax
How is java  Standard library organized?
In one large class hierarchy where the object class is the parent of all classes. every single class implicitly extends the object class
Three pillars of object oriented programs
Encapsulation, inheritance and polymorphism
Define encapsulation
Define iwhentance
Define polymorphism
The ability Of one object to be treated, used like another this works for objects in the inheritance hierarchy
Can me use a reference of a superclass type to refer to an object of its subclass type
Yes
What allows us to place objects from different steps within a class hierarchy into the same array?
Polymorphism
Does polymorphism work bottom up in a class hierarchy?
No! Only top down
What is the instanceOf operator?
Used to keep track of what type of object is being referred to by a variable
. X instanceof Y returns true if X refers to an object of type Y or a subclass (any number of levels down) of Y.
What is casting? In the context of class hierarchy
Changing the type Of a variable (can be risky bc precision loss)
In the context of a class hierarchy it only works downwards
Can casting be done in reverse? Can we use the reference of a subclass type to refer to an object of a superclass type
Yes but also risky
Encapsulation
Defining objects (this is done within class files)
The two main components of an object
Variable declaration and methods
Mutator / accessor methods
Setters & getters
This keyword
Used to distinguish the instance variable from the method parameter
In method overloading WHAT needs to be different it the name is the same?
Its signature (this means types order of its input parameters)
Can constructors be overloaded?
Yes