My Report

Java Methods Online Test – 2


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. Which of these can be overloaded?

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

    class test 
    {
        int a;
        int b;
        test(int i, int j) 
        {
            a = i;
            b = j;
        }
        void meth(test o) 
        {
            o.a *= 2;
            O.b /= 2;
        }          
    }    
    class Output 
    {
        public static void main(String args[])
        {
            test obj = new test(10 , 20);
            obj.meth(obj);
            System.out.println(obj.a + " " + obj.b);        
        } 
    }

3. What is the process of defining two or more methods within same class that have same name but different parameters declaration?

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

class San
{
 public void m1 (int i,float f)
 {
  System.out.println(" int float method");
 }

 public void m1(float f,int i);
  {
  System.out.println("float int method");
  }

  public static void main(String[]args)
  {
    San s=new San();
        s.m1(20,20);
  }
}

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

 
    class overload 
    {
        int x;
 	int y;
        void add(int a)
        {
            x =  a + 1;
        }
        void add(int a , int b)
        {
            x =  a + 2;
        }        
    }    
    class Overload_methods 
    {
        public static void main(String args[])
        {
            overload obj = new overload();   
            int a = 0;
            obj.add(6, 7);
            System.out.println(obj.x);     
        }
    }

6. Which of these is correct about passing an argument by call-by-value process?

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

    class test 
    {
        int a;
        int b;
        void meth(int i , int j) 
        {
            i *= 2;
            j /= 2;
        }          
    }    
    class Output 
    {
        public static void main(String args[])
        {
            test obj = new test();
	    int a = 10;
            int b = 20;             
            obj.meth(a , b);
            System.out.println(a + " " + b);        
        } 
    }

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

 
   class overload 
   {
        int x;
 	double y;
        void add(int a , int b) 
        {
            x = a + b;
        }
        void add(double c , double d)
        {
            y = c + d;
        }
        overload() 
        {
            this.x = 0;
            this.y = 0;
        }        
    }    
    class Overload_methods 
    {
        public static void main(String args[])
        {
            overload obj = new overload();   
            int a = 2;
            double b = 3.2;
            obj.add(a, a);
            obj.add(b, b);
            System.out.println(obj.x + " " + obj.y);     
        }
   }

9. What is the process of defining a method in terms of itself, that is a method that calls itself?

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

    class overload 
    {
        int x;
 	int y;
        void add(int a) 
        {
            x =  a + 1;
        }
        void add(int a, int b)
        {
            x =  a + 2;
        }        
    }    
    class Overload_methods 
    {
        public static void main(String args[])
        {
            overload obj = new overload();   
            int a = 0;
            obj.add(6);
            System.out.println(obj.x);     
        }
   }

 

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.