/
AI Flashcards
Save to my account
Sign up
AI Flashcards
C Plus Plus Object Oriented Concepts
Study
1
Question
What is a class in C++?
Page 1
Answer
A class is a user-defined data type that defines the properties and behaviors of a set of objects. It acts as a blueprint for creating objects.
2
Question
What is an object in C++?
Page 1
Answer
An object is an instance of a class, a concrete entity created from a class that can have a color and shape, for example.
3
Question
What are data members and member functions in a class?
Page 1
Answer
Data members are variables that store the properties of the class, while member functions are functions that define the behaviors of the class.
4
Question
What is encapsulation in C++?
Page 2
Answer
Encapsulation is the mechanism of hiding the internal details of an object and providing access only to what's necessary through public interfaces.
5
Question
What is polymorphism in C++?
Page 2
Answer
Polymorphism allows objects of different classes to be treated as objects of a common superclass, enabling functions to operate on objects without knowing their exact class.
6
Question
Explain the concept of a Student class with data members like name, id, and gpa.
Page 2
Answer
The Student class encapsulates data members such as name (string), id (int), and gpa (float). Each object of the Student class will copy these data members.
7
Question
What is an abstract data type?
Page 2
Answer
An abstract data type is a self-contained entity composed of both data attributes stored in data members and functions defined by member functions that operate on the data.
8
Question
What is a normal member function in C++?
Page 1
Answer
A normal member function is defined outside the class and can only access private members of the class it is defined for.
9
Question
What is an inline member function?
Page 1
Answer
An inline member function is defined inside the class declaration and can directly access the data members.
10
Question
What are the primitive data types in C++?
Page 3
Answer
int, short, long, long long, float, double, char, bool.
11
Question
What is data hiding?
Page 4
Answer
Data hiding is the practice of making data members private to protect them from external access and modification.
12
Question
What is encapsulation?
Page 4
Answer
Encapsulation is the bundling of data members and member functions that operate on that data within a class.
13
Question
What is a static data member?
Page 4
Answer
A static data member is a class variable that is shared among all objects of the class and belongs to the class itself, not to any individual object.
14
Question
What are the different ways of defining data members?
Page 4
Answer
Data members can be defined as private, protected, or public based on access specifiers.
15
Question
What is the syntax for declaring a static data member?
Page 5
Answer
Static data members are declared inside the class with the static keyword and defined outside with the class scope resolution operator.
16
Question
What is the difference between static and non-static data members?
Page 6
Answer
Static members are shared across all objects and belong to the class, while non-static (instance) members are unique to each object.
17
Question
What is a constructor?
Page 5
Answer
A constructor is a special member function that initializes the data members of an object when it is created.
18
Question
What is a constant data member?
Page 5
Answer
A constant data member is a data member declared with const that cannot be modified after initialization.
19
Question
What are access specifiers?
Page 5
Answer
Access specifiers are keywords (public, private, protected) that control the visibility and access to class members.
20
Question
What is private access?
Page 6
Answer
Private members are accessible only by member functions of the same class.
21
Question
What is protected access?
Page 6
Answer
Protected members are accessible by member functions of the same class and derived classes.
22
Question
What is public access?
Page 6
Answer
Public members are accessible from anywhere.
23
Question
What is mutability for objects?
Page 6
Answer
Mutability refers to whether an object can be modified after creation; const objects cannot.
24
Question
How do you declare a class with a constructor?
Page 6
Answer
Use the class keyword, declare members, and define the constructor inside or outside the class.
25
Question
What is the purpose of a constructor?
Page 7
Answer
To initialize the object's data members upon creation.
26
Question
What are the types of constructors?
Page 7
Answer
Default constructor (no parameters), parameterized constructor (with parameters), copy constructor (copies another object).
27
Question
What is a default constructor?
Page 7
Answer
A constructor that takes no arguments and provides default initialization.
28
Question
What is a parameterized constructor?
Page 7
Answer
A constructor that accepts arguments to initialize specific values for data members.
29
Question
What is a copy constructor?
Page 7
Answer
A constructor that initializes an object using another object of the same class.
30
Question
How would you define a Triangle class with width and height parameters?
Page 7
Answer
class Triangle { public: Triangle(float w, float h) : width(w), height(h) {} private: float width, height; };