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

4/7

Page

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

What will be the result of compiling and running the given code?
class A{
      int b=10;
      private A(){
            this.b=7;
      }
      int f(){
            return b;
      }
}
class B extends A{
      int b;
}
public class Test{
      public static void main(String[] args){
            A a = new B();
            System.out.println(a.f());
      }
}

Select an option to see the answer and solution.

Which component is responsible to run java program?

Select an option to see the answer and solution.

Which of the below is not a Java Profiler?

Select an option to see the answer and solution.

What is true about constructor?

Select an option to see the answer and solution.

Which statement is true about java?

Select an option to see the answer and solution.

What is not the use of "this" keyword in Java?

Select an option to see the answer and solution.

When does method overloading is determined?

Select an option to see the answer and solution.

Which of these operators is used to allocate memory for an object?

Select an option to see the answer and solution.

What is true about Class.getInstance()?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Method overriding is combination of inheritance and polymorphism?

Select an option to see the answer and solution.

Which exception is thrown when java is out of memory?

Select an option to see the answer and solution.

What is Recursion in Java?

Select an option to see the answer and solution.

Which function is used to perform some action when the object is to be destroyed?

Select an option to see the answer and solution.

Which of these statement is incorrect?

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;
    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.width=5;
        obj.height=5;
        obj.length=6;
        obj.volume();
    } 
}

Select an option to see the answer and solution.

Which of the following is a garbage collection technique?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What is true about private constructor?

Select an option to see the answer and solution.

Where is a new object allocated memory?

Select an option to see the answer and solution.