My Report

Java Methods 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 is the return type of a method that does not return any value?

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

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

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

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

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

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

8. Which method can be defined only once in a program?

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

10. Which of this statement is incorrect?


 

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.