6. Constructor

Your task is to define a class named Sensor with:

  • constructor that takes an integer id and prints:
    Sensor <id> initialized

 

The program will:

  1. Create a Sensor object with ID 101.
  2. The constructor will run automatically.

     

Example

Output:

Sensor 101 initialized

Why this output?

When the object is created, the constructor prints the initialization message.

 

Question Significance

Introduces constructors — special functions that run automatically when an object is created.

Loading...

Input

Expected Output

Sensor 101 initialized