Welcome to your Java Questions (IT Test) Full Name Contact Number Email ID 1. Predict the output of the following code? 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 2. Consider, public class MyClass{public MyClass(){/code/}// more code…}To instantiate MyClass, you would write? MyClass mc = new MyClass(); MyClass mc = MyClass(); MyClass mc = MyClass; MyClass mc = new MyClass; 3. Predict the output of the following code public class Compute { public static void main (string args [ ]){int result, x ;x = 1 ;result = 0;while (x < = 10) {if (x%2 == 0) result + = x ;+ + x ;}System.out.println(result) ;}} 55 30 25 35 4. Predict the output of the following code public class MyThread implements Runnable { public void run() { System.out.println("running"); } public static void main(String args[]) { Thread t= new Thread(new MyThread()); t.run(); t.run(); t.start(); } } An Exception is thrown at runtime The code executes and prints "running" The code executes and prints "runningrunning" The code executes and prints "runningrunningrunning" 5. Predict the output of the following code public class foo { public static void main (string[]args) { try { return; } finally { system.out.printIn("Finally"); } } } The program runs and prints nothing. The program runs and prints "Finally" The code compiles, but an exception is thrown at runtime. The code will not compile because the catch block is missing 6. Evaluate the following Java expression, if x=3, y=5 and z=10: ++z + y - y + z + x++ 24 23 20 25 7. What will be the output of the following program? public class Test { public static void main(String[] args) { int count = 1; while (count <= 15) { System.out.println(count % 2 == 1 ? "***" : "+++++"); ++count; } } } 1. 15 times *** 2. 15 times +++++ 3. 8 times *** and 7 times +++++ 4. Both will print only once 8. Which of the following for loop declaration is not valid? a. for ( int i = 99; i >= 0; i / 9 ) b. for ( int i = 7; i <= 77; i += 7 ) c. for ( int i = 20; i >= 2; - -i ) d. for ( int i = 2; i <= 20; i = 2* i ) 9. Which package contains the Random class? a. java.util package b. java.lang package c. java.awt package d. java.io package 10. What will be the output of the following program? public class Test2 { public static void main(String[] args) { StringBuffer s1 = new StringBuffer("Complete"); s1.setCharAt(1,'i'); s1.setCharAt(7,'d'); System.out.println(s1); } } 1. Complete 2. Iomplede 3. Cimpletd 4. Coipletd 11. What will be the output of the following program? abstract class MyFirstClass { abstract num (int a, int b) { } } 1. No error 2. Method is not defined properly 3. Constructor is not defined properly 4. Extra parentheses 12. What is the result of the following program? public static synchronized void main(String[] args) throws InterruptedException { Thread f = new Thread(); f.start(); System.out.print("A"); f.wait(1000); System.out.print("B"); } 1. It prints A and B with a 1000 seconds delay between them 2. It only prints A and exits 3. It only prints B and exits 4. A will be printed, and then an exception is thrown. 13. Which of the following option leads to the portability and security of Java? Bytecode is executed by JVM The applet makes the Java code secure and portable Use of exception handling Dynamic binding between objects 14. Which of the following is not a Java features? Dynamic Architecture Neutral Use of pointers Object-oriented 15. _____ is used to find and fix bugs in the Java programs. JVM JRE JDK JDB 16. Which of the following is a valid long literal? ABH8097 L990023 904423 0xnf029L 17. What do you mean by nameless objects? An object created by using the new keyword. An object of a superclass created in the subclass. An object without having any name but having a reference. An object that has no reference. 18. Which option is false about the final keyword? A final method cannot be overridden in its subclasses. A final class cannot be extended. A final class cannot extend other classes. A final method can be inherited. 19. Which of the following is a reserved keyword in Java? object strictfp main system 20. Given, ArrayList list = new ArrayList(); What is the initial quantity of the ArrayList list? 5 10 0 100 21. What will be the output of the following program? abstract class MyFirstClass { abstract num (int a, int b) { } } No error Method is not defined properly Constructor is not defined properly Extra parentheses 22. If three threads trying to share a single object at the same time, which condition will arise in this scenario? Time-Lapse Critical situation Race condition Recursion 23. Which of the following modifiers can be used for a variable so that it can be accessed by any thread or a part of a program? Global transient volatile default 24. To prevent any method from overriding, we declare the method as---- static const final abstract 25. Multiple inheritance means---- one class inheriting from more super classes more classes inheriting from one super class more classes inheriting from more super classes None of the above Time is Up! Time's up