ICSE Class 10 Computer Applications Question 24 of 30

Solved 2024 Question Paper ICSE Class 10 Computer Applications — Question 29

Back to all questions
29
Question

Question 2(ix)

Consider the given program and answer the questions given below:

class temp
{
 int a;
 temp()
 {
 a=10;
 }
 temp(int z)
 {
 a=z;
 }
 void print()
 {
 System.out.println(a);
 }
 void main()
 {
 temp t = new temp();
 temp x = new temp(30);
 t.print();
 x.print();
}
}

(a) What concept of OOPs is depicted in the above program with two constructors?

(b) What is the output of the method main()?

Answer

(a) The concept of Constructor Overloading (Polymorphism) is depicted in the program.

(b) Output of the main() method:

10
30

Explanation:

Output of the program is explained below:

  1. temp t = new temp();
    Calls the default constructor temp()a = 10

  2. temp x = new temp(30);
    Calls the parameterized constructor temp(int z)a = 30

  3. t.print();
    Prints value of a for t10

  4. x.print();
    Prints value of a for x30