Important Introduction to Programming Short Questions
Chapter: 26
Question 1:
What does the keyword 'private' do in a class?
Answer:
The 'private' keyword restricts access to the class's data members and functions, making them accessible only within the class.
Chapter: 26
Question 2:
What is the purpose of the 'public' keyword in a class?
Answer:
The 'public' keyword makes the class's data members and functions accessible from outside the class.
Chapter: 26
Question 3:
What is encapsulation in object-oriented programming?
Answer:
Encapsulation is the concept of hiding the internal implementation of a class and only exposing a public interface.
Chapter: 26
Question 4:
How does encapsulation relate to a real-world example?
Answer:
Encapsulation is like a wristwatch: you can't see the internal mechanisms, but you can use buttons to interact with it.
Chapter: 26
Question 5:
Why is it important to separate interface from implementation?
Answer:
Separating interface from implementation allows the internal workings of a class to change without affecting how users interact with it.
Chapter: 26
Question 6:
How do you declare a class in C++?
Answer:
A class in C++ is declared using the 'class' keyword, followed by the class name and a pair of curly braces that enclose the class's definition.
Chapter: 26
Question 7:
What is the default visibility of data members in a class?
Answer:
The default visibility of data members in a class is private.
Chapter: 26
Question 8:
Why would you use the 'set' functions in a class?
Answer:
'Set' functions are used to assign values to the class's private data members in a controlled manner.
Chapter: 26
Question 9:
How do you call a member function of a class in C++?
Answer:
A member function is called using the object name, followed by the dot operator, and then the function name (e.g., objectName.functionName();).
Chapter: 26
Question 10:
What is a constructor in a class?
Answer:
A constructor is a special member function that is automatically called when an object is created. It usually initializes the object's data members.