Web Design & Application Development

Phoenix, AZ • 480-788-4635

Core Java Questions

Core Java Questions

Interview Questions

1. Can a class be declared as final??

2. Are instance variables assigned a default value?

3. Can you compare a boolean to an int?

4. Can the access specifier for an overriding method allow more or less access than the overridden method?

5. What is the difference between the default and protected access specifier?

6. What are the access levels in order of most restrictive to least?

7. What are the access specifiers in order of most restrictive to least?

8. When you pass a variable as an argument to a method call, what are you passing?

9. What does break do?

10. What does continue do?

11. Where can an anonymous inner class be defined?

12. Can overriding methods throw different exceptions than that of the super?

13. Can a private method be overridden?

14. Can a private method be overridden?

15. Does each source file need a public class in it?

16. What access is the generated constructor given when one is not supplied?

17. What is the keyword transient?

18. What is the keyword native?

19. Will this line compile without errors?

                            Object obj = new Object ();
                          

20. Will this line compile without errors?

                            Object [ ] obj = new Object [7];
                          

21. Will this line compile without errors?

                            Object obj [ ] = new Object [7];
                          

22. Will this line compile without errors?

                            
                              Object obj [ ] = {new Object(), new Object()};
                            
                          

23. Will this line compile without errors?

                            
                              Object obj [ ] = {new Object [1], new Object [2]};
                            
                          

24. Will this line compile without errors?

                            
                              Object [ ] obj = new Object ();
                            
                          

25. Will this line compile without errors?

                            
                              Object obj [ ] = new Object() ;
                            
                          

26. Will this line compile without errors?

                            
                             Object [ ] obj = new Object [ ];
                            
                          

27. Will this line compile without errors?

                            
                             Object obj [ ] = new Object[ ] ;
                            
                          

28. Will this line compile without errors?

                            
                             Object [ ] obj = new Object [3]();
                            
                          

29. Will this line compile without errors?

                            
                             Object obj [ ] = new Object [3]();
                            
                          

30. Will this line compile without errors?

                            
                             Object [8] obj = new Object [ ];
                            
                          

31. Will this line compile without errors?

                            
                             Object [7] obj = new Object [7];
                            
                          

32. Will this line compile without errors?

                            
                             Object [3] obj = new Object [3]() ;
                            
                          

33. Will this line compile without errors?

                            
                             Object obj [] = new {new Object(), new Object()};
                            
                          

34. What best describes the result of the following code segment? The ArrayList sampleArrayList has already been declared and initialized.

                            
                              int i = 63;
                              sampleArrayList.add(i);
                            
                          

35. Will this line compile without errors?

                            
                              double[ ][ ][ ] numbers = new double[ ][ ][ ];
                            
                          

36. Will this line compile without errors?

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

37.Will this line compile without errors?

                            
                              double[ ][ ][ ] numbers = new double[7][ ][ ];
                            
                          

38. Can a constructor have a synchronized modifier?

39. What is the output of the following code segment?

                            
                              int value = 1;
                              switch (value) {
                                case 0:
                                System.out.println("Dog");

                                case 1:
                                System.out.println("Cat");

                                case 1:
                                System.out.println("Fish");

                                default:
                                System.out.println("Cow");
                              }
                            
                          

40. Can a constructor be declared static?

41. Can a top-level class be marked as protected?

42. Can a constructor be declared private?

43. True or False - during arithmetic, when the operands or different types, the resulting type is always the widest of the two type.

44. If break statements are not used in a switch, what will happen?

45. Given:

                            
                              public void simpleTest () {
                                int i;
                                System.out.println(i);
                              }
                            
                          
What will occur?

46. Which of the following are interfaces to ArrayList? List, Map, Queue, RandomAccess, and Set.

47. Fill in the blank. Import statements are ______.

48. What will be printed?

                            
                              System.out.println("roberto".replaceAll("o", "!").substring(1, 7));
                            
                          

49. What will be printed? System.out.println("roberto".substring(3, 7));

50. What will be printed? System.out.println("roberto".replaceAll("o","!").substring(1, 6));

51. What will be printed? System.out.println("roberto".replaceAll("o", "!").substring(2, 7));

52. What version of Unicode is supported by Java SE 7?

53. True or False, octal literals must start with a 0.

54. True or False, octal literals can start with \u.

55. True or False, octal literals can start with \x.

56. In the following code segment, how many times will an even number be sent to standard out?

                            
                              for (int x = 0; x < 10; x++){
                                if (x % 2 == 0) {
                                  System.out.println("x: " + x + " - Even");
                                  continue;
                                }
                                else {
                                  System.out.println("x: " + x + " - Odd");
                                }
                                x++;
                              }
                            
                          

57. What is the new method of the Locale class to Java SE 7?

58. What is missing from the following multi-dimensional array declaration:

                            
                              int[][] array = int[10][10];
                            
                          

59. What is the last value that is sent to standard out for x in the given code segment?

                            
                              int x = 0;
                              do {
                                x = x+2;
                                System.out.println("x: " + x);
                              }
                              while (--x < 5);
                            
                          

60. How can this interface be correctly implemented?

                            
                              public interface TestInterface {
                                public boolean errorState();
                              }
                            
                          

                          
                            public class ClassX implements TestInterface {
                              public boolean errorState() {
                                return false;
                              }
                            }

                            // An object can act as any interface it implements.

                            // and

                            public class ClassX implements TestInterface {
                              private boolean errorState() {
                                return false;
                              }
                            }
                            An object can also act as any of its superclasses.
                          
                        

61. What is the primitive storage range of a byte?

62. java.io.Serializable is a marker interface, also known as a tag interface. What is the unique attribute of marker interfaces?

63. Which literal data types must be cast in order to work with an int data type?

64. InterruptedIOException is a subclass of?

65. ClassNotFoundException is a subclass of?

66. IllegalAccessException is a subclass of?

67. NoSuchMethodException is a subclass of?

68. Which access modifiers can be applied to constructors?

69. If you want to define an unchecked exception, your exception must extend (directly or indirectly) which class?

70. Which lines will not compile?

                            
                              Integer luckyNumber = 66;
                              System.out.println(luckyNumber.booleanValue());
                              System.out.println(luckyNumber.charValue());
                              System.out.println(luckyNumber.byteValue());
                              System.out.println(luckyNumber.shortValue());
                              System.out.println(luckyNumber.longValue());
                              System.out.println(luckyNumber.floatValue());
                              System.out.println(luckyNumber.doubleValue());
                            
                          

71. Will this compile?

                            
                              int ivar = 77;
                              Integer integer = ivar;
                            
                          

72. Which method of the Stringbuilder class attempts to reduce storage used for the character sequence?

73. Which statement is correct?

                            
                              ArrayList d1 = new ArrayList();
                              ArrayList d2 = new ArrayList<>();
                              ArrayList<> d3 = new ArrayList<>();
                              ArrayList<Double> d4 = new ArrayList<>();
                              ArrayList<Double> d5 = new ArrayList<Float>();
                            
                          

74. Running out of Java heap memory is an example of what?

75. What is the value for the variable sum?

                            
                              int[][] sampleArray = new int[3][4];
                              for (int i = 0; i < 3; i++) {
                                sampleArray[i][i+1] = 2;
                              }
                              int sum = 0;
                              for (int i = 0; i < 3; i++) {
                                for (int j = 0; j < 3; j++) {
                                  sum += sampleArray[i][j];
                                }
                              }
                            
                          

76. Is this valid?

                            
                              Object [] o = {"Song Book", 35.95, new Guitar(), 6};
                            
                          

77. Is this valid?

                            
                              short s = 1000s;
                            
                          

78. Java 7's Garbage-First (G1) garbage collector is planned as the long-term replacement of which collector?

79. If a variable is cast to an invalid object, what is the effect?

80.

                            
                              int b1 = 0b_0101_0101_0101_0101;
                              int b2 = 0b_1010_1010_1010_1010;
                              int b3 = b1 & b2;
                              System.out.println("Value:" + b3);
                            
                          
What will be the result?

81. Is this valid?

                            
                              static final long APHELION = 152,097,701;
                            
                          

82. Can a member variable be declared synchronized?