1/29
Flashcards based on the lecture transcript covering core OOPs principles, access modifiers, constructors/destructors, inheritance, polymorphism, abstraction, static members, and language-specific details for C++ and Java.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
What is Object-Oriented Programming (OOP)?
OOP is a programming paradigm based on the concept of objects, which contain both data (fields or attributes) and code (methods or procedures) to manipulate that data.
What core problems in procedural code does Object-Oriented Programming address?
OOP addresses the lack of clear modular structure (via classes), poor code reuse (via inheritance), insecure data (via encapsulation), difficulty in managing large codebases (via abstraction), and difficulty in modeling real-world entities.
What is the difference between a class and an object?
A class is a blueprint or template defining the structure and behavior (data and functions) of objects, whereas an object is a real-world entity or instance of a class created in memory.
How much memory does a class occupy before an object is created?
A class occupies zero memory until an object is created, as memory is allocated for instances, not the class blueprint itself (except for static members).
What is the size of an empty class in C++?
The size of an empty class in C++ is 1 byte, which ensures that each object has a unique memory address.
What are the three access specifiers in C++ and how do they differ?
Private members are accessible only inside the class; protected members are accessible inside the class and by derived classes; public members are accessible to everyone.
In Java, which access level allows visibility to the class, package, and subclasses, but not to the world?
Protected access modifier.
What is a Friend Class in C++?
A friend class in C++ is a class granted special access to directly access the private and protected members of another class.
What is Encapsulation?
Encapsulation is the wrapping of data (attributes) and methods into a single unit called a class, and restricting direct access to internal data using private access modifiers.
What is a constructor and when is it executed?
A constructor is a special method with the same name as the class and no return type that is automatically invoked once at the time of object creation to initialize object values.
What are the three types of constructors?
Non-Parameterized (Default) Constructor, Parameterized Constructor, and Copy Constructor.
What is a destructor in C++?
A destructor is a special member function prefixed with ~ that has no parameters or return type, automatically called to free resources when an object goes out of scope or is deleted.
How does Java manage memory cleanup without destructors?
Java uses an automatic Garbage Collector that identifies and removes unreachable objects from memory to reclaim space and prevent memory leaks.
What are three common use cases for the Scope Resolution Operator (::) in C++?
Accessing a global variable when a local variable shadows it, defining class functions outside the class, and accessing members within namespaces.
What is the 'this' pointer/reference and where is it available?
It is a pointer (C++) or reference (Java) referring to the current object whose method or constructor is executing; it is available only inside non-static member functions.
What is the difference between a Shallow Copy and a Deep Copy?
A Shallow Copy copies memory references/addresses so objects share dynamic memory (modifying one affects the other), while a Deep Copy allocates new memory and copies actual values so objects remain independent.
What happens to base class public and protected members under Private Inheritance in C++?
Both public and protected members of the base class become private members in the derived class.
Are private members of a base class inherited by a derived class in C++?
Private members are not directly accessible in the derived class, but they still exist in the base class portion of the derived object.
What is the Diamond Problem in multiple inheritance?
It is an ambiguity issue occurring when a derived class inherits from two classes that share a common base class, making it unclear which parent copy of the base member should be accessed.
How is the Diamond Problem resolved in C++?
By using Virtual Inheritance (e.g., class B : virtual public A) so that only a single shared copy of the base class is inherited.
Why does Java not encounter the Diamond Problem with classes?
Java does not support multiple inheritance using classes; it only supports multiple inheritance through interfaces.
What is Compile-time Polymorphism (Static Binding) and how is it achieved?
It is when the method to execute is determined at compile time based on signature; it is achieved via Method/Function Overloading (Java & C++) and Operator Overloading (C++ only).
What are the main rules for Method Overloading?
The method name must be the same, parameters must differ in number, type, or order, and varying the return type alone does not constitute overloading.
What is Run-time Polymorphism (Dynamic Binding) and how is it achieved?
It is when the method to execute is determined at runtime based on the actual object type; it is achieved via Method Overriding using base class pointers/references and virtual functions.
What is a Virtual Function in C++?
A base class member function declared with the 'virtual' keyword, instructing the compiler to use dynamic (late) binding so the correct overridden derived method is invoked at runtime.
What happens in C++ if a derived object is deleted using a base pointer without a virtual destructor in the base class?
Only the base class destructor is invoked, leading to undefined behavior and potential memory leaks.
How is an Abstract Class defined in C++?
An abstract class in C++ is a class that contains at least one Pure Virtual Function (declared with = 0) and cannot be instantiated.
What are three key differences between Abstract Classes and Interfaces in Java?
1) Abstract classes use 'extends' (single class) while interfaces use 'implements' (multiple interfaces allowed); 2) Abstract classes can have constructors, while interfaces cannot; 3) Abstract class fields can be instance/static with any modifier, while interface fields are strictly public static final.
What is a Static Data Member?
A static data member is a variable shared across all objects of a class that is allocated only once in memory and exists even before any object is created.
What is the key restriction on Static Member Functions?
Static member functions belong to the class and can be invoked without creating an object, but they can only directly access static data members and static functions.