IEO Level 2- English Olympiad (SOF) Class 9 Coaching Programs

⏳ 🎯 Online Tests (2 Tests [50 Questions Each]): NTA Pattern, Analytics & Explanations

Click Here to View & Get Complete Material

Rs. 200.00

3 Year Validity (Multiple Devices)

🎓 Study Material (303 Notes): 2024-2025 Syllabus

Click Here to View & Get Complete Material

Rs. 450.00

3 Year Validity (Multiple Devices)

🎯 250 MCQs (& PYQs) with Full Explanations (2024-2025 Exam)

Click Here to View & Get Complete Material

Rs. 200.00

3 Year Validity (Multiple Devices)

Classes and Objects with Constructors⟋Destructors: Creating Objects

Illustration: Classes and Objects with Constructors⟋Destructors: Creating Objects

Example 1

  1. # include <iostream.h >
  2. class student
  3. {
  4. private :
  5. char name [ 80 ];
  6. int rn ;
  7. float marks ;
  8. private :
  9. void getdata ( ) ;
  10. void putdata ( ) ;
  11. };
  12. void student :: getdata ( )
  13. {
  14. cin name rn marks ;
  15. }
  16. void student :: putdata ( )
  17. {
  18. cout name rn marks ;
  19. }
  20. void main ( )
  21. {
  22. student st ;
  23. st. getdata ( ) ;
  24. st. putdata ( ) ;
  25. }
Illustration: Classes and Objects with Constructors⟋Destructors: Creating Objects

Creating Objects

  • An object is an instance of a class and it can be created by using class name. student st; Object can be created.
  • When a class is defined by placing their names immediately after the closing brace.
  1. class student
  2. {
  3. } x, y, z ;
  4. </chart>

The above definition would create the object x, y and z of type student.