7. Constructor with Parameters

Your task is to define a class named UART with:

  • constructor that takes two parameters:
    • int baudRate
    • char parity
  • The constructor should print:
     

UART initialized with baud=<baudRate>, parity=<parity>

 

The program will:

  1. Create a UART object with values 9600 N.
  2. The constructor will automatically print the initialization message.
     

Example

Output:

UART initialized with baud=9600, parity=N

Why this output?

The constructor receives the parameters 9600 and 'N' and prints them during object creation.

 

Question Significance

Shows how constructors can accept parameters, making object creation flexible and context-aware.

Loading...

Input

Expected Output

UART initialized with baud=9600, parity=N