Page 322 - CA_Blue( J )_Class10
P. 322
4. Which of the following is an example of constructor overloading?
a. Multiple variables with the same name b. Multiple methods with the same name
c. Multiple classes with the same name d. Multiple constructors with the same name
5. Consider the following class definition. What will be the output?
class program
{
int x;
program()
{
this(10);
System.out.println("Default constructor");
System.out.println("Value of x is "+x);
}
program(int x)
{
this.x = x;
System.out.println("Parameterized constructor ");
System.out.println("Value of x "+x);
}
public static void main()
{
program obj = new program();
}
}
a. Default constructor b. Default constructor
Value of x is 10
Parameterized constructor
Value of x 10
c. Parameterized constructor d. Default constructor
Value of x 10 Value of x 10
Default constructor
Value of x is 10
6. What will be the output of the following code?
class program
{
program() {
System.out.println("Default constructor");
}
program(int x) {
System.out.println("Parameterized constructor");
}
public static void main(String[] args) {
program obj1 = new program();
program obj2 = new program(10);
}
}
a. Default constructor b. Parameterized constructor
Default constructor Parameterized constructor
c. Default constructor d. Parameterized constructor
Parameterized constructor Default constructor
7. What will happen if a class has a parameterized constructor, but no default constructor, and you try to create an object using the
default constructor?
a. The object is created successfully b. A compilation error occurs
c. A runtime error occurs d. The default constructor is created automatically
320320 Touchpad Computer Applications-X

