Flashcards
revature week 2
Cards in this deck (24)
- 1What is the purpose of inheritance?The point of inheritance is to have classes inherit the properties and behaviors of
another class
For example instead of defining the exact same properties and behaviors over and over again
for each specific type of Vehicle, we can just inherit from a base class called Vehicle. - 2What is a superclass / base class?Superclass/base-class/parent class = A class higher in the hierarchy (Vehicle)
- 3What is a subclass / child class?subclass / child class is a class lower in the hierarchy
For example superclass / parent class would be Vehicle and subclass would be Motorcycles or Jdm - 4What does the subclass inherit from the super class?They inherit the properties and behaviors of the parent and the grandparent etc..
- 5What is the purpose of super()?used to call parent class constructors and to call parent class variables and methods but super can only be used from the parent class.
- 6What is method overriding?Method overriding requires you to have the exact same number and type of parameters
The method you want to override is located in a parent class
The overriding method is a method defined in the child class - 7How is method overriding different than method overloading?Method overloading is a way of defining multiple methods with the same name but different number of parameters or different types of parameters
- 8If Dog extends Animal, can you use an Animal reference variable to point to a Dog object?Yes, because we can use the super keyword to call parent class variables.
- 9If a method is first defined in the Dog class (not overridden from the Animal class), can we invoke that method from an Animal reference variable? If not, what do we need to do with that Animal reference variable?we would need to do downcasting
- 10What is special about the Object class?if you do not
explicitly have the
extends keyword on a
class, it will
automatically extend
from Object - 11What methods does the Object class contain?toString() method
hashCode() method
equals() method - 12What is the purpose of overriding the equals() method?the String class overrides the equals method from the object class to compare two different string object to see if they are the same.
- 13If we do not override the equals() method, how does its implementation in the Object class work??
- 14What is the purpose of overriding the toString() method??
- 15If we do not override the toString() method, what does it do by default??
- 16When overriding the equals() method, why do we also need to override the hashCode() method??
- 17What access modifiers are there?public
private
protected
default - 18What is the difference between protected and default access modifiers?protected: fields or methods can be accessible from another class within the same package or a class that is a subclass
default: this access modifier can only be accessed within the same package - 19What are the four pillars of OOP?the four pillars of OOP are
Inheritance
Polymorphism
Encapsulation
Abstraction - 20What is polymorphism?the ability of an object to take many forms. It allows us to perform the same action in many different ways using method overloading and overriding
- 21Is method overloading compile-time or runtime polymorphism, and why?compile-time polymorphism. The compiler takes our source code and
converts it into bytecode instructions that contain execution paths for the JVM when it is running
the bytecode. So, when we do method overloading, it knows what execution path to take - 22Is method overriding compile-time or runtime polymorphism, and why?runtime polymorphism. The JVM checks to see what type of object the
variable is actually pointing to as the program is running - 23What is encapsulation?wrapping data into a single unit
Encapsulation is about restricting direct access to variables defined inside of a class and
requiring the use of getters/setters to modify the information - 24What is abstraction?
Information
- Description
- Coding Flashcards on revature week 2, created by Ruben Michel on 26/10/2021.
- Created by
- Ruben Michel
- Views
- 1
- Rating