Home / Questions / Create a class with one integer instance variable. Initialize the variable using: default constructor parameterized constructor
Explanatory Question

Create a class with one integer instance variable. Initialize the variable using:

  1. default constructor
  2. parameterized constructor

👁 100 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation


class Number {
    int a;

    public Number() {
        a = 0;
    }

    public Number(int x) {
        a = x;
    }
}