Week 8 - OOP - Object Oriented Programming Principles and Intermediate Java Flashcards
4 pillars of OOP
Abstraction
Inheritence
Polymorphisim
Encapsulation
What is inheritance?
Inheritance is all about inheriting the common state and behavior of parent class (super class) by its derived class (sub class or child class). A sub class can inherit all non-private members from super class, by default.
Inheritance can be one of four types – depending on classes hierarchy. Name them:
Single inheritance
Multi-level inheritance
Hierarchical inheritance
Multiple inheritance
What is Single inheritance
There is one Parent class and one Child class. One child class extends one parent class
Multi-level inheritance
In multilevel inheritance, there will be inheritance between more than three classes in such a way that a child class will act as parent class for another child class.
Hierarchical inheritance
In hierarchical inheritance, there is one super class and more than one sub classes extend the super class.
Multiple inheritance
In multiple inheritance, a class can inherit the behavior from more than one parent classes as well.
____ is a type of inheritance where there is one Parent class and one Child class. One child class extends one parent class.
Single inheritance
____ is a type of inheritance where there is one super class and more than one sub class extend the super class.
Hierarcihal inheritance
What is an object class?
a special class in Java which is the root class from which all other classes inherit, either directly or indirectly.
The _____ method returns a copy of this object.
clone
The _____ method returns a Class object that represents this object’s runtime class
getClass
The _____ method returns a String representation of this object.
toString
In java equals() method is used to compare equality of
two Objects
_____ is the default implementation of the equals() method which only checks if two object references refer to the same object.
Shallow comparison
_____ is where data members of objects are to be compared with one another.
Deep comparison
During the execution of the application, if hashCode() is invoked more than once on the same object then it must consistently return the same Integer value. T/F
True
Different executions of the same application using hashcode() must produce the same integer every time. T/F?
False
What is polymorphism?
“taking on many forms”. In the realm of programming, it describes how objects can behave differently in different contexts. The most common examples of polymorphism are method overloading and overriding.
What is method overloading ?
is when there exist two or more methods in a class with the same method name, but different method signatures by changing the parameter list.
What is method overriding>
is when a method in a child class has the same method signature as a method in the parent class, but with a different implementation. Thus, child classes can change the default behavior given by a parent’s method. Overriding methods makes class hierarchies more flexible and dynamic.
What does object-oriented programming mean?
Programming constructs are objects which model real-world concepts and can be put into hierarchies, and the relationship between objects are managed
What is the difference between classes and objects?
Classes are the templates from which objects are instantiated
What does polymorphism mean?
Allowing the implementation of a given behavior to vary, whether between subclasses or within the same class