Java MCQ's on Constructors
This test contains 10 questions based on Constructors.
Each question answered correctly awards you 1 point and each incorrect answer has a penalty of -0.25 points, no points are deducted for unattempted answers.
Each question answered correctly awards you 1 point and each incorrect answer has a penalty of -0.25 points, no points are deducted for unattempted answers.
Select Test Type
You Get +1 for each correct answer and -0.25 for each incorrect answer
Time Left -
minutes
:
seconds
What is the return type of Constructors?
| int | float |
| void | None of these |
Which keyword is used by method to refer to the object that invoked it?
| import | catch |
| this | super |
Which of the following is a method having same name as that of its class?
| finalize | constructor |
| delete | class |
Which operator is used by Java run time implementations to free the memory of an object when it is no longer needed?
| delete | free |
| new | None of these |
Which function is used to perform some action when the object is to be destroyed?
| finalize() | delete() |
| main() | None of these |
What is the output of this program?
class Box {
int width;
int height;
int length;
int volume;
public Box() {
width = 5;
height = 5;
length = 6;
}
void volume() {
volume = width*height*length;
}
}
class Output {
public static void main(String args[])
{
Box obj = new Box();
obj.volume();
System.out.println(obj.volume);
}
}
| 100 | 150 |
| 200 | 250 |
What will be the output of the following program ?
class Equality {
Integer x;
Integer y;
boolean isequal() {
return(x == y);
}
}
class Output {
public static void main(String args[])
{
Equality obj = new Equality();
obj.x = 5;
obj.y = 5;
System.out.println(obj.isequal()); }
}
| True | False |
| 0 | 1 |
What will be the output of the following program ?
class Box {
int width;
int height;
int length;
int volume;
void finalize() {
volume = width*height*length;
System.out.println(volume);
}
protected void volume() {
volume = width*height*length;
System.out.println(volume);
}
}
class Output {
public static void main(String args[])
{
Box obj = new Box();
obj.volume();
}
}
| Compilation error | Runtime error |
| 0 | 100 |
Which of the folowing stements are incorrect?
| Default constructor is called at the time of declaration of the object if a constructor has not been defined. | finalize() method is called when a object goes out of scope and is no longer needed. |
| finalize() method must be declared protected. | Constructor can be parameterized. |
What will be the output of this program?
class Area {
int width;
int length;
int area;
public Area(int width, int length) {
this.width = width;
this.length = length;
}
}
class Output {
public static void main(String args[])
{
Area obj = new Area(5 , 6);
System.out.println(obj.length + " " + obj.width);
}
}
| 0 0 | 5 5 |
| 5 6 | 6 5 |
Finish Test
No comments: