Advertisements
Advertisements
प्रश्न
Consider and give the output of the following program:
class report
{ int a,b;
report()
{ a=10;
b=15;
}
report(int x, int y)
{ a=x;
b=y;
}
void print()
{ System.out.println(a*b);
}
static void main()
{ report r = new report();
r.print();
report p = new report(4, 5);
p.print();
}
}कोड लेखन
Advertisements
उत्तर
150
20
Explanation:
When the object r of the Report class is created for the first time, the default constructor is invoked, and the variables a and b are initialized to 10 and 15, respectively. Therefore, the print() function outputs 150.
When the object p is created next, the parameterized constructor is called, initializing a and b with the values 4 and 5. Hence, the print() function produces 20.
shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
2024-2025 (March) Official Board
