Quiz #1 Flashcards
Definition: Determining the set of features (properties and methods) that a class will have.
Abstraction
What are the two main properties of an object?
- Properties (data/variables)
2. Methods
Everything in Java is an object, except:
Primitive data types
Definition: The collection of code that contains the instructions for building an object.
Class
What are the three pillars of object oriented programming?
- Encapsulation
- Inheritance
- Polymorphism
Which concept of OOP deals with visibility modifiers and access to data and methods of a class?
Encapsulation
Basic idea of encapsulation:
Being able to control access to an object’s properties and methods
Which concept of OOP deals with the extension of classes?
Inheritance
Basic idea of inheritance:
A sub-class (child class) can inherit methods from its super class (parent class)
Every class in Java inherits methods and properties from what class?
Object Class
Which concept of OOP deals with method over-riding?
Polymorphism
What are two other ways to say polymorphism?
- Late binding
2. Dynamic binding
What is the difference between method overloading and method over-riding?
Method over-riding involves creating methods of the same name in DIFFERENT classes of the same hierarchy.
What is like a blueprint, or recipe in OOP?
Classes
What is an instance of a class?
An Object
What is an object?
A named instance of a class held in memory, consisting of methods and properties.
What is the state of an object?
The values held in it’s data variables
What is known as an object’s behaviour?
It’s Methods.
What does UML stand for?
Unified Modeling Language
UML: What does an italicized name mean?
Abstract
UML: What do the +, -, and # mean
+ == public
- == private
# == protected
UML: What does an underline mean?
Static
If you don’t specify an access modifier, what visibility does it have?
Default visibility: Only classes in the same package can view it.
What is a constructor method?
A constructor method is the method used to instantiate an object in memory.
What are the two ways that constructor methods are different from all other methods?
- Begins with an uppercase (because it’s named the same as the class)
- no return type is ever specified.
How do we make an object if we don’t write a constructor method?
Java provides one to us, called the default constructor
What happens once we define our own constructor methods?
The default constructor is no longer available.
What is a static method?
A class method, means that an object does not need to be made to use the method.
What is an object method called?
Instance Method
What is special about a static variable?
It is visible to every method in a class. Every object made of that class has access to the SAME variable.
Which visibility modifier is only accessible within the class?
Private
Which visibility modifier is only accessible by classes in the same package, but NOT by sub-classes from other packages?
Default (no modifier)
Which visibility modifier is accessible by classes in the same package AND child classes?
Protected
Which visibility modifier is visible by anything?
Public
What kind of method is used to return information about an object’s state?
Accessors or Getters
What kind of method is used to change the value or state of an object?
Mutator or Setters
What word is usually found in an accessor method’s name?
“get”
What word is usually found in a mutator method’s name?
“set”
What are 2 other names for the parent class?
- Base Class
2. Super Class
Which pillar of OOP deals with the accessibility of methods and attributes from extended classes?
Inheritance
How many super classes can a child class have?
1
What kind of inheritance is Java?
Single Inheritance
Which methods and attributes do sub-classes inherit from the super-class?
Any that are not declared as private
What is meant by “inheritance is one way only”?
Sub-classes can inherit from the super-class, but the super-class gains nothing from the sub-classes.
What is the mother of all classes?
The Object Class
What part of the class hierarchy are abstract methods typically made?
Higher Up (super-class)
What is missing with an abstract method?
Body code
What must be included in a child class constructor?
A call to the superclass using the keyword “super”
The first line in a sub-class constructor method?
Call to the super
When does dynamic binding take place?
Runtime
What is polymorphism?
The ability of the JVM to determine which version of an over-ridden method to run.
What is another way to say dynamic binding?
Late binding
What is the rule about visibility modifiers with regards to over-riding an abstract method in a sub-class?
Visibility modifier in the child class can be no more restrictive than in the base class
Can a non-abstract class hold an abstract method?
No
What does polymorphism apply to?
Only methods
How must an object be instantiated to take advantage of polymorphism?
Referenced by a variable of the super class, and using the constructor of the sub class.
Is an object of an abstract class able to be instantiated?
No
Is an object of an abstract class ever created in memory?
Yes
Can an object created using an abstract super variable use the methods from the sub-class?
No
Can a sub-class be abstract if the base class is not?
Yes
What are the 7 public methods all objects inherit from the object class?
- toString()
- equals()
- getClass()
- hashCode()
- notify()
- notifyAll()
- wait()
What are the 2 protected methods inherited from the object class?
- finalize()
2. clone()
What is special about data values in an interface?
They are constants by default
What is an interface?
A type of class that provides abstract methods and constant values
What are the 2 main uses of interfaces?
- Implementing a common function throughout a large number of classes
- Simulate multiple inheritance
What keyword is used for classes using an interface?
Implements
What is the keyword used when an interface’s method has body code?
default
Can a static method in an interface be over-ridden?
No
Can a default method in an interface be over-ridden?
Yes
Can you instantiate an object from an interface?
No
What is an interface with only one method?
A Functional Interface
What is a difference in how an interface extends another interface?
Interfaces can extend multiple other interfaces, unlike classes which are single-parent.
Can a class only implement 1 interface?
No, as many as it wants.