My Report

Java Constructor Online Test – 1


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. What will be the output of the following Java code?

class San
{
     San()throws IOException
     {
  
     } 
 
}
class Foundry extends San
{
     Foundry()
     {

     }
     public static void main(String[]args)
     {
  
     }
}

2. 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);
        }
   }

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

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

5. 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);        
        } 
    }

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

7. Which of the following statements are incorrect?

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

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

10. What is the return type of Constructors?


 

Start practicing “1000 MCQs on Java”, and once you are ready, you can take tests on all topics by attempting our “Java Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.