Wednesday, February 16, 2011

Java interview questions


1.  What is java run time environment?
2.  How java is platform independent language?
3.  What is difference between compiler and interpreter?
4.  Java is secure language. Why?
5.  Why main function in java is static?
6.  What is abstract class and what is use of abstract class?
7.  Why a class cannot be static?
8.  Why abstract class cannot be final?
9.  What are final class, final method and final variable?
Answer:
A final class is special type of class which cannot be inherited i.e. we cannot create any subclass of final class. All the methods and variables of final class are also final.
A final method is special type of method which cannot be overridden in the subclass.
A final variable is special type of variable which after assigning a value at the time of declaration we cannot modified its value. It is necessary to initialize the final variable at the time of declaration.
10. What is default access specifier?
11. What is static import in java?
12. What is difference between checked and unchecked exception?
13. What is wrapper class in java?
14. What is generic?
15. What is difference between throw and throws keyword?
16. Can interface implements another interface?
17. Is it possible that any class which extends an abstract class and doesn’t override all the method of that abstract class?
18. Is it true, all the methods and member variables of final class is also final? If it is true then why and if is false then why?
19. Can abstract class have a method which has body?
20. What is automatic type casting?
21. Why in java array can be declared as: int [] array;
22. Can a method whose return type is void have return keyword?
23. What is task of >>> operator?
24. What is meaning of variable number of argument in java?
25. What are difference between private, protected, public and default access specifiers?
26. What are the non access specifiers in java?
27. What is error in the declaration: float f=5.5;
28. Which of the following comparison more appropriate and why?
(a) if (a==5)
(b) if (5==a)
29. What are differences between following two if statements
(a) if (a&b)
(b) if (a&&b)
30. What is meaning of multiple catch clauses?
31. What is meaning of package in java?
32. What is difference between path and classpath command?
33. What is meaning of access protection?
34. Defined interface?
35. What are difference between class and interface?
36. What is use of this keyword?
37. How can you find the class name of given object?
38. Can exception in java can be cause of compilation error? If yes then why?
39. What are the properties of nested interface?
40. What is nested class?
41. Can class be protected? Why?
42. Can class be private? Why?
43. What are the properties of constructor?
44. What is default constructor?
45. What are uses of super keyword?
Answer:
(a) It is used to access the super class member variable from subclass either it is hidden in subclass or not.
(b) It is used to access the super class method from the subclass either it has overridden in subclass or not.
(c) In method form super keyword is used to call super class constructor.
46. What is dynamic method dispatch?
47. What is difference between c++ and java?
48. Give any examples of run time polymorphism.
49. What is difference between late and early binding?
50. What is encapsulation?
51. What is difference between overloading and overriding?
52. What is difference between final, finally and finalize ()?
Answer:
finalize (): It is method of Object class. This method is called by java garbage collector when garbage collector think there is not any reference of object of any class and it deletes the object of that class automatically.
53. What is meaning of abstraction?
54. How can you delete any object in java?
55. What is garbage collection in java?
56. Why java doesn’t support multiple inheritances?
57. How can you say java is robust language?
58. Define inheritance.
Answer:
Inheritance is mechanism by which we can derive a new class from a already existing class. New class is called subclass or child class while exiting class is called as super class or sub class. Sub class may inherit some or all properties of super class. For this we use extends keyword in java. So, inheritance is based on the concept of reusability.
59. What is JVM?

No comments:

Post a Comment