ICSE Class 10 Computer Applications Question 5 of 19

Constructors — Question 5

Back to all questions
5
Question

Question 5

Write a class specifier (along with its constructor) that creates a class student having two private data members : rollno and grade and two public functions init( ) and display( ).
(Do not write full definitions of member functions except for constructor).

Answer
class student
{
    private int rollno;
    private char grade;

    public student()    {
        rollno = 0;
        grade = '\0';
    }

    public student(int roll, char g)
    {
        rollno = roll;
        grade = g;
    }

    public void init()  {}
    
    public void display()   {}
}