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