1. What does the synchronized keyword on a method do?
2. A deadlock error occurs when a Java program
3. How do you declare a destructor in Java?
4. Do we need to import the java.lang package at anytime?
5. Which is correct way of importing an entire package ‘pkg’?
6. which is a correct statement:
7. Consider the following code snippet String river = new String(“Columbia”); System.out.println(river.length()); What is printed?
8. Consider public class MyClass{ public MyClass(){/*code*/} // more code... } To instantiate MyClass, you would write?
9. What is a token?
10. Suppose ArrayList x contains two strings [Beijing, Singapore]. Which method will cause the list to become [Beijing, Chicago, Singapore]?
11. Which primitive types is unsigned?
12. Difference between Vector and ArrayList?
13. What is transient variable?
14. Which is not a legal identifier?
15. package test; public class Test { } -------- package test.subtest; public class SubTest extends Test{} Does this code compile without errors?
16. String x = 'abc'; In this code, abc is:
17. Which line will not throw a compile time error?
18. Which keywords is used to make a class?
19. What is the stored in the object obj in following lines of code? box obj;
20. Output of the following program? class Output { public static void main(String args[]) { int arr[] = {1, 2, 3, 4, 5}; for ( int i = 0; i < arr.length - 2; ++i) System.out.println(arr[i] + ' '); } }
21. Which is the correct list of entities of the Composite Entity pattern?
22. Which classes/set of classes can illustrate polymorphism in the given code? abstract class student { public : int marks; calc_grade(); } class topper:public student { public : calc_grade() { return 10; } }; class average:public student { public : calc_grade() { return 20; } }; class failed{ int marks;};
23. Which is correct about the Creational Design patterns?
24. Which statement is true about local inner class within a method?
25. Which statement about threading is incorrect?
26. Which statement is correct with regard to Polymorphism?
27. Which is wrapper classes?
28. Which cannot apply to constructors?
29. What would happen on trying to compile and run the following code? class House { public final void MaintainMethod() { System.out.println('MaintainMethod'); } } public class Building extends House { public static void main(String argv[]) { House h = new House(); h.MaintainMethod(); } }
30. What would happen on trying to compile and run the following code? private class Crack { } public class Manic { transient int numb; public static void main(String sparrow[]) { } }
31. Which help increase the code clarity?
32. Which require explicit try/catch exception handling by the programmer?
33. Output of the following line? System.out.println(Math.floor(-2.1));
34. Assuming that val has been defined as an int for the code below, which values of val will result in 'Test C' being printed? if( val > 4 ) { System.out.println('Test A'); }else if( val > 9 ) { System.out.println('Test B'); }else System.out.println('Test C');
35. Which method will cause a thread to stop?
36. Which interface is used by implementations of models for JTable?
37. Two functions are defined with the same name and same return type. The first one accepts string input parameter type and the second one accepts integer. This represents Abstraction.
38. Choose the correct statements:
39. Choose all valid forms of the argument list for the FileOutputStream constructor shown below:
40. Which statement will not compile?
41. OQL stands for:
42. Select all statements that are true?
43. Which statement is true about using generics? Select all true statements.
44. There are three classes named A, B, and C. The class B is derived from class A and class C is derived from B. Which of the following relations are correct for the given classes?
45. Which option is a valid JSP declaration?
46. Which statement is correct regarding the 'synchronized' keyword?
47. What method signature will work with this code? boolean healthyOrNot = isHealthy(
48. Which are valid keywords in a Java module descriptor (module-info.java)?
49. Which characteristic does not apply to instances of java.util.HashSet=
50. You have an instance of type Map named instruments containing the following key-value pairs: guitar=1200, cello=3000, and drum=2000. If you add the new key-value pair cello=4500 to the Map using the put method, how many elements do you have in the Map when you call instruments.size()?
51. You have a variable of named employees of type List containing multiple entries. The Employee type has a method getName() that returns te employee name. Which statement properly extracts a list of employee names?
Java MCQs | Topic-wise