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

7/7

Page

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

What will be the output of the following Java code?
class area 
{
    int width;
    int length;
    int area;
    void area(int width, int length) 
    {
        this.width = width;
        this.length = length;
    }

}    
class Output 
{
    public static void main(String args[])
    {
        area obj = new area();
        obj.area(5 , 6);
        System.out.println(obj.length + " " + obj.width);        
    } 
}

Select an option to see the answer and solution.

What will be the output of the following Java program?
class main_class 
{
    public static void main(String args[])
    {
        int x = 9;
        if (x == 9) 
        { 
            int x = 8;
            System.out.println(x);
        }
    } 
}

Select an option to see the answer and solution.

What is -Xms and -Xmx while starting jvm?

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(6));
    }
}

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();
         obj.width = 10;
         obj.height = 2;
         obj.length = 10;
         int y = obj.width * obj.height * obj.length; 
         System.out.print(y);
    } 
}

Select an option to see the answer and solution.

What is the process of defining more than one method in a class differentiated by method signature?

Select an option to see the answer and solution.

Which of the following statements is correct?

Select an option to see the answer and solution.

Which of this statement is incorrect?

Select an option to see the answer and solution.

Which concept of Java is achieved by combining methods and attribute into a class?

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(1));
    }
}

Select an option to see the answer and solution.

How to get prints of shared object memory maps or heap memory maps for a given process?

Select an option to see the answer and solution.

Which of these is not a correct statement?

Select an option to see the answer and solution.

Which of these data types is used by operating system to manage the Recursion in Java?

Select an option to see the answer and solution.

Which of the following is a method having same name as that of its class?

Select an option to see the answer and solution.

Which method can be defined only once in a program?

Select an option to see the answer and solution.

Which operator is used by Java run time implementations to free the memory of an object when it is no longer needed?

Select an option to see the answer and solution.

What is the extension of java code files?

Select an option to see the answer and solution.

When Overloading does not occur?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What happens to the thread when garbage collection kicks off?

Select an option to see the answer and solution.