OOP studying Flashcards
What is OOP?
Programming paradigm that relies on the concept of classes and objects. It is used to structure a software program into simple, reusable pieces of code.
What is a class?
Blueprint of an object. User defined data type and can also encapsulate functions. Stored in heap memory/dynamic memory.
What is an object?
Instance of a class. An attribute or characteristic.
What is Encapsulation?
Methods/functions and variables in a class. Makes code look cleaner. Example – Element ID associated to buttons on the android app. Swipe functionality.
What is Inheritance
Allows classes to inherit features of other classes. Supports reusability. We inherit certain properties from the class ‘Human’ such as the ability to speak, breathe, eat, drink, etc
What is Abstraction?
Hiding the implantation details. Example – Header files. ATM.
What is Polymorphism?
Same function or object behaves differently in different scenarios. Example – Dogs are used to herd sheep but not all dogs herd sheep.
What is Function/Method overloading?
Two or more functions with same name but different parameters
What is Function/Method overriding?
Creating a new version of an old function in the child class
What is Data hiding?
Put data in a class and declare it as private. Prevents honest mistakes.
What are pointers?
Is a variable that stores a memory address
What is a reference variable?
Is an address that indicates where an object’s variables and methods are stored
What is a linked list?
is a linear collection of data elements. Each element points to the next
What are access specifiers?
Public – accessible from outside the class Private – accessible from other members of the same class
What is an inline function?
Actual code is in the function
“this” pointer
refers to the current object of a class
What is a structure?
Also a user defined data type. Stored in stack memory.
What is a constructor?
A special construct that creates objects. no return type. same name as class.
What is a default constructor?
A constructor with no parameters.
What is a Parameterized constructor?
Constructor with parameters
What is a copy constructor?
Creates a new object as a copy of an existing object
What is a destructor?
Happens automatically when an object is removed. Same name as the class. “~” tilde
Memory allocation
“New” is used for memory allocation
“delete” is used for memory deallocation
What is Multi-threading?
Multiple threads are executed simultaneously. Each thread starts its own stack based on the flow (or) priority of the threads.
What is a Thread?
the flow of execution is called Thread. Every java program has at least one thread called the main thread
How is Java different from C++?
C++ allows users to use pointers in the program.
What is the main objective of garbage collection?
is to free up the memory space occupied by the unnecessary and unreachable objects during the Java program execution by deleting those unreachable objects.
Disadvantages of a Multithreaded Application
Difficulty of debugging
It is much harder to replicate an error in a multithreaded application than it is to do so in a single-threaded