Name –
Roll No. –
Stream –
Q1. What is the difference between an Inner Class and a Sub-Class?
Ans:
Q2. What are the various access specifiers for Java classes?
Ans:
Q3. What's the purpose of Static methods and static variables?
Ans:
Q4. What is data encapsulation and what's its significance?
Ans:
Q5. What is a singleton class? Give a practical example of its usage.
Ans:
Q6. What are Loops in Java? What are the three types of loops?
Ans:
Q7: What is an infinite Loop? How infinite loop is declared?
Ans:
Q8. What is the difference between continue and break statement?
Ans:
Q9. What is the difference between double and float variables in Java?
Ans:
Q10. What is the Final Keyword in Java? Give an example.
Ans:
Q11. What is ternary operator? Give an example.
Ans:
Q12: How can you generate random numbers in Java?
Ans:
Q12: How can you generate random numbers in Java?
Ans:
Q14. What's the base class in Java from which all classes are derived?
Ans:
Q14. What's the base class in Java from which all classes are derived?
Ans:
Q16. What are Java Packages? What's the significance of packages?
Ans:
Q17. Can we declare a class as Abstract without having any abstract method?
Ans:
Q18. What’s the difference between an Abstract Class and Interface in Java?
Ans:
Q19. What are the performance implications of Interfaces over abstract classes?
Ans:
Q20. Does Importing a package imports its sub-packages as well in Java?
Ans:
Q21. Can we declare the main method of our class as private?
Ans:
Q22. How can we pass argument to a function by reference instead of pass by value?
Ans:
Q23. How is an object serialized in java?
Ans:
Q24. When we should use serialization?
Ans:
Q25. Is it compulsory for a Try Block to be followed by a Catch Block in Java for
Exception handling?
Ans:
Q26. Is there any way to skip Finally block of exception even if some exception occurs
in the exception block?
Ans:
Q27. When the constructor of a class is invoked?
Q28. Can a class have multiple constructors?
Ans:
Q29. Can we override static methods of a class?
Ans:
Q30. In the below example, what will be the output?
Ans:
Q31. Is String a data type in java?
Ans:
Q32. In the below example, how many String Objects are created?
String s1="I am Java Expert";
String s2="I am C Expert";
String s3="I am Java Expert";
Ans:
Q33. Why Strings in Java are called as Immutable?
Ans:
Q34. What's the difference between an array and Vector?
Ans:
Q35. What is multi-threading?
Ans:
Q36. Why Runnable Interface is used in Java?
Ans:
Q37. What are the two ways of implementing multi-threading in Java?
Ans:
Q38. When a lot of changes are required in data, which one should be a preference to
be used? String or StringBuffer?
Ans:
Q39. What's the purpose of using Break in each case of Switch Statement?
Ans:
Q40. How garbage collection is done in Java?
Ans:
Q41. How we can execute any code even before main method?
Ans:
Q42. Can a class be a super class and a sub-class at the same time? Give example.
Ans:
Q43. How objects of a class are created if no constructor is defined in the class?
Ans:
Q44. In multi-threading how can we ensure that a resource isn't used by multiple
threads simultaneously?
Ans:
Q45. Can we call the constructor of a class more than once for an object?
Ans:
Q46. There are two classes named classA and classB. Both classes are in the same
package. Can a private member of classA can be accessed by an object of classB?
Ans:
Q47. Can we have two methods in a class with the same name?
Ans:
Q48. How can we make a copy of a java object?
Ans:
Q49. What's the benefit of using inheritance?
Ans:
Q50. What’s the default access specifier for variables and methods of a class?
Ans:
Q51. Give an example of the use of Pointers in Java class.
Ans:
Q52. How can we restrict inheritance for a class so that no class can be inherited from
it?
Ans:
Q53. What’s the access scope of Protected Access specifier?
Ans:
Q54. What's difference between Stack and Queue?
Ans:
Q55. In java, how we can disallow serialization of variables?
Ans:
Q56. How can we use primitive data types as objects?
Ans:
Q57. Which types of exceptions are caught at compile time?
Ans:
Q58. Describe different states of a thread.
Ans:
Q59. Can we use a default constructor of a class even if an explicit constructor is
defined?
Ans:
Q60. Can we override a method by using same method name and arguments but
different return types?
Ans:
Q61.What will be the output of the following piece of code?
public class operatorExample {
public static void main (String args[]) {
int x=4;
system.out. println(x++);
}
}
Ans:
Q62. A person says that he compiled a java class successfully without even having a
main method in it? Is it possible?
Ans:
Q63. Can we call a non-static method from inside a static method?
Ans:
Q64. What are the two environment variables that must be set in order to run any Java
programs?
Ans:
Q65. Can variables be used in Java without initialization?
Ans:
Q66. Can a class in Java be inherited from more than one class?
Ans:
Q67. Can a constructor have a different name than a Class name in Java?
Ans:
Q68. What will be the output of Round (3.7) and Ceil (3.7)?
Ans:
Q69: Can we use goto in Java to go to a particular line?
Ans:
Q70. Can a dead thread be started again?
Ans:
Q71. Is JDK required on each machine to run a Java program?
Ans:
Q72. What's the difference between comparison done by equals method and ==
operator?
Ans:
Q73. Is it possible to define a method in Java class but provide it's implementation in
the code of another language like C?
Ans:
Q74. How are destructors defined in Java?
Ans:
Q75. Can a variable be local and static at the same time?
Ans:
Q76. Can we have static methods in an Interface?
Ans:
Q77. In a class implementing an interface, can we change the value of any variable
defined in the interface?
Ans:
Q78. Is it correct to say that due to garbage collection feature in Java, a java program
never goes out of memory?
Ans:
Q79. Can we have any other return type than void for main method?
Ans:
Q80. I want to re-reach and use an object once it has been garbage collected. How it's
possible?
Ans:
Q81. In Java thread programming, which method is a must implementation for all
threads?
Ans:
Q82. I want to control database connections in my program and want that only one
thread should be able to make database connection at a time. How can I implement
this logic?
Ans:
Q83. How can an exception be thrown manually by a programmer?
Ans:
Q84. I want my class to be developed in such a way that no other class (even derived
class) can create its objects. How can I do so?
Ans:
Q85. How objects are stored in Java?
Ans:
Q86. How can we find the actual size of an object on the heap?
Ans:
Q87. Which of the following classes will have more memory allocated?
Class A: Three methods, four variables, no object
Class B: Five methods, three variables, no object
Ans:
Q88. What happens if an exception is not handled in a program?
Ans:
Q89. I have multiple constructors defined in a class. Is it possible to call a constructor
from another constructor's body?
Ans:
Q90. What’s meant by anonymous class?
Ans:
Q91. Is there a way to increase the size of an array after its declaration?
Ans:
Q92. If an application has multiple classes in it, is it okay to have a main method in
more than one class?
Ans:
Q93. I want to persist data of objects for later use. What's the best approach to do so?
Ans:
Q94. What is a Local class in Java?
Ans:
Q95. String and String Buffer both represent String objects. Can we compare String
and String Buffer in Java?
Ans:
Q96. Which API is provided by Java for operations on a set of objects?
Ans:
Q97. Can we cast any other type to Boolean Type with type casting?
Ans:
Q98. Can we use different return types for methods when overridden?
Ans:
Q99. What's the base class of all exception classes?
Ans:
Q100. What's the order of call of constructors in inheritance?
Ans: