Objects and Classes
Introduction
A class is a blueprint; an object is an instance of that class created at runtime.
Definition
Class: blueprint. Object: instance of a class.
C++ Code Example
class Student { int roll; string name; };
int main(){
Student s1, s2; // objects
}Important Questions
Short Questions
- Define class.
- Define object.
- Difference class vs object?
- What is instance?
Long Questions
- Explain class and object with example.
- Differentiate class and object.
MCQ Practice
1. A class is a:
- Blueprint
- Instance
- Variable
- Function
Answer: Blueprint.
2. An object is a:
- Instance
- Blueprint
- Keyword
- Operator
Answer: Instance.
3. Objects are created at:
- Runtime
- Compile time
- Link time
- Never
Answer: Runtime.
4. Multiple objects share:
- Class definition
- Unique data
- Both
- None
Answer: Unique data.
5. class keyword introduces:
- Class definition
- Object
- Function
- Variable
Answer: Class definition.
Quick Revision
- Class = blueprint; Object = instance.
- Objects hold data; class defines behavior.