Consider the following program segment and answer the questions below:

ICSE Class 10 Computer Applications PYQ · 2025 Specimen · Section A

2(ix)1 Mark · 2025 · Section A · 2025 Specimen

Consider the following program segment and answer the questions below:

class calculate

{
  int a; double b; 
  calculate()

  {

  a=0; 
  b=0.0;

  }

  calculate(int x, double y)

  {

  a=x;
  b=y;

  }

void sum()

{

  System.out.println(a*b);

}}

Name the type of constructors used in the above program segment?

Show SolutionHide Solution↓

The type of constructors used in the above program segment are:

  1. Default constructor
  2. Parameterized constructor

Explanation:

The types of constructors used in the given program are:

1. Default Constructor:

calculate() {
    a = 0;
    b = 0.0;
}
  • A default constructor is a constructor that does not take any parameters.
  • It initializes the instance variables a and b with default values (0 and 0.0 respectively).

2. Parameterized Constructor:

calculate(int x, double y) {
    a = x;
    b = y;
}
  • A parameterized constructor is a constructor that takes arguments (int x and double y in this case).
  • It allows for initializing the instance variables a and b with specific values provided during object creation.
← Previous questionNext question →

Browse the free Computer Applications sample bank