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

6/7

Page

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

What is it called where object has its own lifecycle and child object cannot belong to another parent object?

Select an option to see the answer and solution.

What will be the output of the following Java program?
class recursion 
{
    int fact(int n) 
    {
        int result;
        if (n == 1)
            return 1;
        result = fact(n - 1) * n;
        return result;
    }
} 
class Output 
{
    public static void main(String args[]) 
    {
        recursion obj = new recursion() ;
        System.out.print(obj.fact(5));
    }
}

Select an option to see the answer and solution.

Which of the below is not a memory leak solution?

Select an option to see the answer and solution.

Which of the below is invalid identifier with the main method?

Select an option to see the answer and solution.

What is the extension of compiled java classes?

Select an option to see the answer and solution.

What is the return type of a method that does not return any value?

Select an option to see the answer and solution.

What is use of interpreter?

Select an option to see the answer and solution.

What would be the behaviour if this() and super() used in a method?

Select an option to see the answer and solution.

Which of the following is a type of polymorphism in Java?

Select an option to see the answer and solution.

What would be the behaviour if one parameterized constructor is explicitly defined?

Select an option to see the answer and solution.

Which of the following statements are incorrect?

Select an option to see the answer and solution.

What is it called if an object has its own lifecycle and there is no owner?

Select an option to see the answer and solution.

What is true about protected constructor?

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 obj = new box();
         System.out.println(obj);
     } 
 }

Select an option to see the answer and solution.

In the following Java code, which call to sum() method is appropriate?
class Output 
{
 
        public static int sum(int ...x)
        {
             return; 
        }
        static void main(String args[]) 
        {    
             sum(10);
             sum(10,20);
             sum(10,20,30);
             sum(10,20,30,40);
        } 
}

Select an option to see the answer and solution.

How can we identify whether a compilation unit is class or interface from a .class file?

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;
    int volume;
    void volume(int height, int length, int width) 
    {
         volume = width*height*length;
    } 
}    
class Prameterized_method
{
    public static void main(String args[])
    {
        box obj = new box();
        obj.height = 1;
        obj.length = 5;
        obj.width = 5;
        obj.volume(3,2,1);
        System.out.println(obj.volume);        
    } 
 }

Select an option to see the answer and solution.

Which of these will happen if recursive method does not have a base case?

Select an option to see the answer and solution.

What would be behaviour if the constructor has a return type?

Select an option to see the answer and solution.

Which keyword is used by the method to refer to the object that invoked it?

Select an option to see the answer and solution.