NIOS Computer: Chapter 13 – Classes & Objects with Constructors/Destructors Part 2

Doorsteptutor material for UGC is prepared by world's top subject experts: Get detailed illustrated notes covering entire syllabus: point-by-point for high retention.

Download PDF of This Page (Size: 243K)

Image of Create object

Image of Create Object

Image of Create object

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.     stgetdata ( ) ;
  24.     stputdata ( ) ;
  25. }
Image of class and object

Image of Class and Object

Image of class and object

1. 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. xyz ;
  4. </chart>

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

Developed by: