MSD Java Test

Which statement is true regarding an object?
An object is what classes instantiated are from
An object is an instance of a class
An object is a variable
An object is a reference to an attribute
The wrapping up of data and functions into a single unit is called
Encapsulation
Abstraction
Data Hiding
Polymorphism
Which statement is not true in java language?
A public member of a class can be accessed in all the packages.
A private member of a class cannot be accessed by the methods of the same class.
A private member of a class cannot be accessed from its derived class.
A protected member of a class can be accessed from its derived class.
Where is array stored in memory?
Heap space and stack space
Stack space
Heap space
First generation memory
What is parent class of Hashtable?
Map
Dictionary
HashSet
None of these
Mutual exclusive and inter-thread communication are which type of Synchorization?
Thread Synchronization
Process Synchronization
Object Synchronization
None of the above
What is known as the classes that extend Throwable class except RuntimeException and Error?
Unchecked Exception
Checked Exception
Error
None of the above
What is used to execute parameterized query?
Statement interface
PreparedStatement interface
ResultSet interface
None of the above

What is the output of below program?

public class Example {

      public static void main(String[] args) {

StringBuffer sb = "Hello";

sb.append("world");

System.out.println(sb.tostring());

      }

}

Helloworld
Run time exception
Hello world
Compile error

What is the output of below program?

class myclass {

    public static void main(String[] args) {

        for(int I = 0; true; i++) {

            System.out.println("Hello");

            break;

        }

    }

}

Compile error
Infinite loop
Hello
None of these

What is the output of below program?

class class1 {

   public static void main(String args[]) {

       System.out.println(fun());

   }

   static int fun() {

       static int x= 0;

       return ++x;

   }

}

Compile error
1
0
Runtime exception

What is the output of below program?

package pkg;

  

class Base {

    public void Print() {

        System.out.println("Base");

    }         

}

  

class Derived extends Base {    

    public void Print() {

        System.out.println("Derived");

    }

}

  

class Main{

    public static void display( Base o ) {

        o.Print();   

    }

    public static void main(String[] args) {

        Base x = new Base();

        Base y = new Derived();

        Derived z = new Derived();

        display (x);

        display (y);

        display (z);

    }

}

Base Derived Base
Base Base Derived
Base Derived Derived
Derived Derived Derived

What is the output of below program?

public class test{
      public static void main(String args[]){
            int I = 0;
            I = i++ + I;
            System.out.println(“I = ” +i);
      }
}

 
I = 0
I = 1
I = 2
Compile-time Error.

What is the output of below program?

public class myclass {

public static int foo(int a, String s){
      s = “Yellow”;
      a=a+2;
      return a;
}
public static void bar(){
      int a=3;
      String s = “Blue”;
      a = foo(a,s);
      System.out.println(“a=”+a+” s=”+s);
}
public static void main(String args[]){
      bar();
}

}

A = 3 s = Blue
A = 5 s = Yellow
A = 3 s = Yellow
A = 5 s = Blue

What is the output of below program?

class class1  {

                        public static void main(String args[])

                        {   

                             int sum = 0;

                             for (int I = 0, j = 0; I < 5 & j < 5; ++i, j = I + 1)

                                 sum += I;

                                     System.out.println(sum);

                        }

                    }

 

5
6
14
Compile error

What is the output of below program?

class Output

{

        public static void main(String args[])

        {   

           final int a=10,b=20;

           while(a<b)  {

               System.out.println("Hello");

          }

          System.out.println(" World");

 

        }

}

Hello
Run time error
Hello World
Compile error

What is the output of below program?

class First {

                public First() { System.out.print("a"); }

}

 

class Second extends First {

                public Second() { System.out.print("b"); }

}

 

class Third extends Second {

                public Third() { System.out.print("c"); }

}

 

public class MainClass  {

                public static void main(String[] args) {

                                Third c = new Third();

                }

}

C
Cba
Abc
None of these

What is the output of below program?

public class ArrayParam2 {

      public void updateParam( double[] x )  {

                 x[0] = 10.5; 

      }  

      public static void main(String[] args)  {

                 double[] a = {2.5, 5.0};

   

                ArrayParam2 obj = new ArrayParam2();

   

                 obj.updateParam( a );          

   

                 for (int I = 0; I < a.length; i++)

                    System.out.print( a[i] );

       }

   }

2.5 5.0
10.5 5.0
2.5 10.5
12.5 5.0

What is the output of below program?

public class priorityQueue  {

    public static void main(String[] args)

    {

        PriorityQueue<Integer> queue =   new PriorityQueue<>();

        queue.add(11);

        queue.add(10);

        queue.add(22);

        queue.add(5);

        queue.add(12);

        queue.add(2);

  

        while (queue.isEmpty() == false)

            System.out.printf("%d ", queue.remove());

  

        System.out.println("\n");

    }

}

11 10 22 5 12 2
2 12 5 22 10 11
2 5 10 11 12 22
22 12 11 10 5 2

What is the output of below program?

public class test  {

                static {

                                System.out.printf("%d", 1);

                }

                static {

                                System.out.printf("%d", 2);

                }

                static {

                                System.out.printf("%d", 3);

                }

                private static int myMethod() {

                                return 4;

                }              

private int function() {

                                return 5;

                }

                public static void main(String[] args) {

                                System.out.printf("%d", (new javaclass()).function() + myMethod());

                }

}

9
1239
54
12354
{"name":"MSD Java Test", "url":"https://www.quiz-maker.com/QPREVIEW","txt":"Which statement is true regarding an object?, The wrapping up of data and functions into a single unit is called, Which statement is not true in java language?","img":"https://www.quiz-maker.com/3012/images/ogquiz.png"}
Powered by: Quiz Maker