OOP Basic Flashcards
Inner Class
also nested class, group class together to be more readable and maintainable (can be private or protected)
Sub Class
Class that inherits from another class
Static methods
method directly accessible without instantiating an object
Static variable
variable directly accessible without instantiating an object
4 Principles of OOP
Encapsulation
Polymorphism
Abstraction
Inheritance
Example/Definition of Encapsulation
Encapsulation is an attribute of an object, and it contains all data which is hidden. That hidden data can be restricted to the members of that class.
Levels are Public, Protected, Private, Internal, and Protected Internal.
Overriding
allow subclass or child class to provide specific implementation (same signature)
Overloading
same method name different signature
Abstract Class
class declared abstract, may or may not include abstract methods. Cannot be instantiated but can be inherited
Interface
completely abstract class used to group related methods with empty bodies. It is a concept of OOPs that allows you to declare methods without defining them.
Interface vs Abstract Class
Abstract Class
- Can have both abstract and non abstract method
- Can be private, public,
- Can provide the implementation of an interface
Interface
- Only Abstract methods
- public by default
- cannot provide implementation of an abstract class
Specifiers
Public - Visible to all classes
Protected - Visible to clases with in the package and subclasses of other package
Default - Visible to the classes within the package
Private - Visible within the class. Not accessible outside the class
Example/Definition Polymorphism
Polymorphism is nothing but assigning behavior or value in a subclass to something that was already declared in the main class. Simply, polymorphism takes more than one form.
Example/Definition Inheritance
Inheritance is a concept where one class shares the structure and behavior defined in another class. If Inheritance applied to one class is called Single Inheritance, and if it depends on multiple classes, then it is called multiple Inheritance.
Example/Definition of Abstraction
Abstraction is a useful feature of OOPS, and it shows only the necessary details to the client of an object. Meaning, it shows only required details for an object, not the inner constructors, of an object. Example – When you want to switch on the television, it is not necessary to know the inner circuitry/mechanism needed to switch on the TV. Whatever is required to switch on TV will be shown by using an abstract class.