16. Object Declaration and Function Access

We have already defined a class LED with two public functions:

  • void turnOn() → prints
    LED ON
  • void turnOff() → prints
    LED OFF

Your task is to:

  1. Declare an LED object in main().
  2. Call turnOn() and then turnOff() on that object.
     

Example

Output:

LED ON
LED OFF

Why this output?

Because the program first calls turnOn(), which prints "LED ON", and then turnOff(), which prints "LED OFF".

 

Question Significance

This shows how to access class methods using an object, the most common way to control behavior in C++.

Loading...

Input

Expected Output

LED ON LED OFF