Java Language | 10 Minute‐Test 16


Instruction

  • Total number of questions : 10.
  • Time alloted : 10 minutes.
  • Each question carry 1 mark.
  • No Negative marks
  • DO NOT refresh the page.
  • All the best :-).

1.

Which of the following statements is correct?

A.
Public method is accessible to all other classes in the hierarchy
B.
Public method is accessible only to subclasses of its parent class
C.
Public method can only be called by object of its class.
D.
Public method can be accessed by calling object of the public class.

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

2.

What is the output of this 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());

        }

    }

A.
false
B.
true
C.
0
D.
1

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

3.

What is the output of this program?

class San{

     San()throws IOException

     {

      }

 }

class Foundry extends San{

     Foundry()

     {

      }

     public static void main(String[]args)

     {

      }

}

A.
compile time error
B.
run time error
C.
compile and runs fine
D.
unreported exception java.io.IOException in default constructor

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

If parent class constructor throws any checked exception, compulsory child class constructor should throw the same checked exception as its parent, otherwise code won’t compile.

4.

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

          } 

 }

A.
6
B.
7
C.
8
D.
9

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

5.

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

             }

   }

A.
2 3
B.
3 3
C.
Runtime Error
D.
Compilation Error

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

6.

What is the output of this program?

    class access{

       static int x;

       void increment(){

           x++;

       } 

       }

       class static_use {

        public static void main(String args[])

        {

            access obj1 = new access();

            access obj2 = new access();

            obj1.x = 0;

               obj1.increment();

            obj2.increment();

            System.out.println(obj1.x + " " + obj2.x);

            }

   }

A.
1 2
B.
1 1
C.
2 2
D.
Compilation Error

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

All objects of class share same static variable, all the objects share same copy of static members, obj1.x and obj2.x refer to same element of class which has been incremented twice and its value is 2.

7.

What is the output of this program?

    class string_class {

        public static void main(String args[])

        {

            String obj = "I LIKE JAVA";

               System.out.println(obj.charAt(3));

        }

    }

A.
I
B.
L
C.
K
D.
E

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

charAt() is a method of class String which gives the character specified by the index. obj.charAt(3) gives 4th character i:e I.

8.

What is the output of this program?

    class A {

        int i;

    }   

    class B extends A {

        int j;

        void display() {

            super.i = j + 1;

            System.out.println(j + " " + i);

        }

    }   

    class inheritance {

        public static void main(String args[])

        {

            B obj = new B();

            obj.i=1;

            obj.j=2;  

            obj.display();    

        }

   }

A.
2 2
B.
3 3
C.
2 3
D.
3 2

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None

9.

What is the output of this program?

class Alligator

 {

  public static void main(String[] args)

   {

   int []x[] = {{1,2}, {3,4,5}, {6,7,8,9}};

   int [][]y = x;

   System.out.println(y[2][1]);

   }

 }

A.
2
B.
3
C.
7
D.
Compilation Error

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Both x,and y are pointing to the same array

10.

What is the output of this program?

    abstract class A {

        int i;

        abstract void display();

    }   

    class B extends A {

        int j;

        void display() {

            System.out.println(j);

        }

    }   

    class Abstract_demo {

        public static void main(String args[])

        {

            B obj = new B();

            obj.j=2;

            obj.display();   

        }

   }

A.
0
B.
2
C.
Runtime Error
D.
Compilation Error

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

class A is an abstract class, it contains a abstract function display(), the full implementation of display() method is given in its subclass B, Both the display functions are the same. Prototype of display() is defined in class A and its implementation is given in class B.


Submit your test now to view the Results and Statistics with answer explanation.