Vidyalelo
Java Programming · all questions

Constructors and Methods
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

140

Questions

5/7

Page

Pick an option on a question to see the right answer and solution.

What will be the output of the following Java program?
class box 
{
    int width;
    int height;
    int length;
    int volume;
    void volume() 
    {
         volume = width*height*length;
    } 
}    
class Output 
{ 
    public static void main(String args[])
    {
        box obj = new box();
        obj.height = 1;
        obj.length = 5;
        obj.width = 5;
        obj.volume();
        System.out.println(obj.volume);        
    } 
}

Select an option to see the answer and solution.

Which of the following is a method having same name as that of it's class?

Select an option to see the answer and solution.

What is the stored in the object obj in following lines of Java code?
box obj;

Select an option to see the answer and solution.

Which concept of Java is a way of converting real world objects in terms of class?

Select an option to see the answer and solution.

Which component is responsible to optimize bytecode to machine code?

Select an option to see the answer and solution.

What will be the output of the following Java code?
class box 
{
    int width;
    int height;
    int length;
    int volume;
    box() 
    {
        width = 5;
        height = 5;
        length = 6;
    }
    void volume() 
    {
         volume = width*height*length;
    } 
}    
class constructor_output 
{
    public static void main(String args[])
    {
        box obj = new box();
        obj.volume();
        System.out.println(obj.volume);
    }
}

Select an option to see the answer and solution.

Which of the following is a valid declaration of an object of class Box?

Select an option to see the answer and solution.

What is it called where child object gets killed if parent object is killed?

Select an option to see the answer and solution.

Which of these keywords is used to make a class?

Select an option to see the answer and solution.

Which component is responsible for converting bytecode into machine specific code?

Select an option to see the answer and solution.

What is false about constructor?

Select an option to see the answer and solution.

Which of these packages contains the exception Stack Overflow in Java?

Select an option to see the answer and solution.

What will be the output of the following Java program?
class equality 
{
    int x;
    int 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());
    } 
}

Select an option to see the answer and solution.

What will be the output of the following Java program?
class box 
{
    int width;
    int height;
    int length;
} 
class mainclass 
{
    public static void main(String args[]) 
    {        
        box obj1 = new box();
        box obj2 = new box();
        obj1.height = 1;
        obj1.length = 2;
        obj1.width = 1;
        obj2 = obj1;
        System.out.println(obj2.height);
    } 
}

Select an option to see the answer and solution.

What is the return type of Constructors?

Select an option to see the answer and solution.

Which of the following has the highest memory requirement?

Select an option to see the answer and solution.

What will be the output of the following Java code?
class A
{
     A()throws IOException
     {
 
     } 
 
}
class B extends A
{
     B()
     {
 
     }
     public static void main(String[]args)
     {
 
     }
}

Select an option to see the answer and solution.

Abstract class cannot have a constructor.

Select an option to see the answer and solution.

Which of the following is not OOPS concept in Java?

Select an option to see the answer and solution.

Garbage Collection can be controlled by a program?

Select an option to see the answer and solution.