Ask Question
11 April, 01:33

class secretType { public: static int count; static int z; secretType (); secretType (int a); void print (); static void incrementY (); private: int x; static int y; }; secretType::secretType () { x = 1; } secretType::secretType (int a) { x = a; } void secretType::print () { cout << "x = " << x << ", y = " << y << "z = " << z << ", count = " << count << endl; } static void secretType::incrementY () { y++; } Consider the accompanying class and member functions definitions. How many constructors are present in the class definition?

+5
Answers (1)
  1. 11 April, 01:42
    0
    The answer to this question can be given as:

    In this class definition, there are two constructors.

    Explanation:

    In the class definition two constructors are different in type but first we explain constructor that can be as:

    Constructor: constructor are special member functions whose task is to initialized as an object of its class.

    Rule for defining constructor:

    A constructor doesn't have a return type not even void.

    The name of the constructor must be the same as the class name.

    A constructor is called automatically when a new instance of an object is created.

    Type of constructor:

    default constructor. parameterized constructor. copy constructor.

    In the question there are two type of constructor is used that can be given as:

    default constructor:

    The constructor without any parameters is called a default constructor. This type of constructor is called automatically when a new instance of an object is created.

    parametrized constructor:

    In the parameterized constructor we use at least one parameter in the constructor that is called the parameterized constructor. In the parameterized constructor we can initialize each instance of the class with several values.

    Example:

    class AB / /define class

    {

    String name; / /define variable

    AB () / /default constructor

    {

    System. out. print ("hello ... "); / /message.

    }

    AB (String name) / /parametrized constructor.

    {

    this. name = name; / /holding value in name variable.

    }

    }

    class Main / /define class

    {

    public static void main (String[] args) / /main method

    {

    AB OB1 = new AB (); / /creating class object.

    AB ob2=new AB ("XYZ");

    System. out. print (ob2. name); / /print value

    }

    }

    Output:

    hello ... XYZ
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “class secretType { public: static int count; static int z; secretType (); secretType (int a); void print (); static void incrementY (); ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers