JAVA Classes and Methods Mcqs

Our collections of Multiple choice questions and answers focuses on study of Java Classes and Methods . These questions are chosen from a collection of most authoritative and best reference books on Java Classes and Methods. Our aim is to prepare an individual for competitive exams like NTS, GAT, ECAT, University and College entrance exams and various tests and job interviews. One should practice our Mcqs to assimilate Java Classes and Methods comprehensively.

  1. Home
  2. »
  3. Languages
  4. »
  5. Programming Languages Mcqs
  6. »
  7. Java Programming Mcqs
  8. »
  9. Java Classes and Methods Mcqs
  10. »
  11. Page 3

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

Copy of argument is made into the formal parameter of the subroutine

Reference to original argument is passed to formal parameter of the subroutine

Copy of argument is made into the formal parameter of the subroutine and changes made on parameters of subroutine have effect on original argument

Reference to original argument is passed to formal parameter of the subroutine and changes made on parameters of subroutine have effect on original argument

34.
What is the output of the following code?

class Compscibits
{
 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)
  {
    Compscibits c=new Compscibits();
        c.m1(20,20);
  }
}

Int float method

Float int method

Compile time error

Run time error

35.
What is the output of this program?

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

5

6

7

8

36.
What is the output of this program?

    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

7

8

9

39.
Which of the following statements are incorrect?

Public members of class can be accessed by any code in the program

Private members of class can only be accessed by other members of the class

Private members of class can be inherited by a subclass, and become protected members in subclass

Protected members of a class can be inherited by a subclass, and become private members of the subclass

40.
What is the output of this program?

    class access
    {
        public int x;
  private int y;
        void cal(int a, int b)
        {
            x =  a + 1;
            y =  b;
        }        
    }    
    class access_specifier 
    {
        public static void main(String args[])
        {
            access obj = new access();   
            obj.cal(2, 3);
            System.out.println(obj.x + " " + obj.y);     
        }
   }

3 3

2 3

Runtime Error

Compilation Error

41.
What is the output of this program?

    class access
    {
        public int x;
  private int y;
        void cal(int a, int b)
        {
            x =  a + 1;
            y =  b;
        }   
        void print() 
        {
            system.out.println(" " + y);     
        } 
    }   
    class access_specifier 
    {
        public static void main(String args[])
        {
            access obj = new access();   
            obj.cal(2, 3);
            System.out.println(obj.x);
            obj.print();     
        }
   }

2 3

3 3

Runtime Error

Compilation Error

45.
How can a protected modifier be accessed?

Accessible only within the class

Accessible only within package

Accessible within package and outside the package but through inheritance only

Accessible by all

46.
What happens if constructor of class A is made private?

Any class can instantiate objects of class A

Objects of class A can be instantiated only within the class where it is declared

Inherited class can instantiate objects of class A

Classes within the same package as class A can instantiate objects of class A

error: You are not allowed to do so.....
0Shares
0
Scroll to Top