15. Object Declaration and Variable Access

We have already defined a class Device with:

  • A public integer variable id.
     

Your task is to:

  1. Declare a Device object in main().
  2. Assign the value 101 to id.
  3. Print:
    Device ID: 101


Example

Output:

Device ID: 101

Why this output?

The program assigns 101 to the id variable inside the object and then prints it.

 

Question Significance

This is the most basic usage of a class: declaring an object and printing one of its variables.

Loading...

Input

Expected Output

Device ID: 101